<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
Zapatec Calendar Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="calendar-core.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>Zapatec Calendar</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>calendar-core.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		No overview generated for 'calendar-core.js'<BR/><BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="Zapatec/Calendar.html">Zapatec.Calendar</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/*
 * $Id: calendar-core.js 16946 2009-04-09 09:07:54Z nmaxim $
 * The Zapatec DHTML Calendar
 *
 * Copyright (c) 2004-2009 by Zapatec, Inc.
 * http://www.zapatec.com
 * 1700 MLK Way, Berkeley, California,
 * 94709, U.S.A.
 * All rights reserved.
 *
 * Main Calendar file. Creates a popup or flat calendar with various options.
 *
 * Original version written by Mihai Bazon,
 * http://www.bazon.net/mishoo/calendar.epl
 */</span>

<span class="comment">// $Id: calendar-core.js 16946 2009-04-09 09:07:54Z nmaxim $</span>

<span class="comment">// Emulate window.event in Mozilla for certain events</span>
zapatecUtils.emulateWindowEvent([
	<span class="literal">'dblclick'</span>
]);

<span class="comment">/**
 * Zapatec Calendar widget class. Extends base Zapatec Widget class
 * (utils/zpwidget.js).
 *
 * &lt;pre&gt;
 * &lt;strong&gt;In addition to config options defined in base Zapatec.Widget class
 * provides following config options:&lt;/strong&gt;
 *
 *	inputField				| the ID of an input field to store the date
 *	displayArea				| the ID of a DIV or other element to show the date
 *	button					| ID of a button or other element that will trigger the calendar
 *	eventName				| event that will trigger the calendar, without the "on" prefix (default: "click")
 *	closeEventName			| event that will close the calendar (i.e. one can use "focus" for eventName and "blur" for closeEventName)
 *	ifFormat					| date format that will be stored in the input field
 *	daFormat					| the date format that will be used to display the date in displayArea
 *	singleClick				| (true/false) wether the calendar is in single click mode or not (default: true)
 *	firstDay					| numeric: 0 to 6.  "0" means display Sunday first, "1" means display Monday first, etc.
 *	align						| alignment (default: "Br"); if you don't know what's this see the calendar documentation
 *	range						| array with 2 elements.  Default: [1900.0, 2999.12] -- the range of years available
 *	weekNumbers				| (true/false) if it's true (default) the calendar will display week numbers
 *	flat						| null or element ID; if not null the calendar will be a flat calendar having the parent with the given ID
 *	flatCallback			| function that receives a JS Date object and returns an URL to point the browser to (for flat calendar)
 *	disableFunc				| function that receives a JS Date object and should return true if that date has to be disabled in the calendar
 *	onSelect					| function that gets called when a date is selected.  You don't _have_ to supply this (the default is generally okay)
 *	onClose					| function that gets called when the calendar is closed.  [default]
 *	onUpdate					| function that gets called after the date is updated in the input field.  Receives a reference to the calendar.
 *	onFDOW					| an event handler that is fired when a user click on the day name.
 *	onWeekClick				| an event handler that is fired when a user click on the week number.
 *	onTodayClick			| an event handler that is fired when a user click on the today button.
 *	onMonthSelect			| an event handler that is fired when a user choose a month (buttons or combo).
 *	onYearSelect			| an event handler that is fired when a user choose a year (buttons or combo).
 *	onHisrotySelect		| an event handler that is fired when a user choose a history date (buttons or combo).
 *	noGrab					| prevents calendar from adding document event handlers to intercept key events or to close the calendar when it is clicked outside
 *	onCreate					| an event handler that is fired when calendar create.
 *	date						| the date that the calendar will be initially displayed to
 *	showsTime				| default: false; if true the calendar will include a time selector
 *	timeFormat				| the time format; can be "12" or "24", default is "12"
 *	electric					| if true (default) then given fields/date areas are updated for each move; otherwise they're updated only on close
 *	sortOrder				| ("asc"(ending)/"desc"(ending)/"none"). If "asc" (default), order of the multiple dates (when multiple dates is on) will be sorted in ascending order. Otherwise, it will be sorted in descending order. "none" means no sorting is needed.
 *	step						| configures the step of the years in drop-down boxes; default: 2
 *	position					| configures the calendar absolute position; default: null
 *	cache						| if "true" (  default: "true") it will reuse the same calendar object, where possible
 *	showOthers				| if "true" (but default: "false") it will show days from other months too
 *	multiple					| array of multiple dates
 *	multipleRange			| array of multiple range dates (use only with timeRange)
 *	multipleSelection		| boolean, if true calendar can use multiple selection
 *	saveDate					| if set (default unset) will save a cookie for this duration.
 *	numberMonths			| Have the calendar display multiple months
 *	stepMonths			  | Step for next and previous arrows in months. Default: numberMonths.
 *	controlMonth			| When displaying multiple months, this will be the control month. Default 1.
 *	vertical					| When displaying multiple months, months can progress in a vertical or horizontal way. Horizontal is the default.
 *	monthsInRow				| When displaying multiple months how many months in a horizontal row. Works both in vertical and horizontal mode. Default numberMonths
 *	fdowClick				| Allow click on Days of Week 1st day
 *	titleHtml				| Html you can put in title of calendar
 *	noHelp					| Disables "?" button in your calendar
 *	noHistory				| Disable history
 *	noStatus					| Disable status bar
 *	noCloseButton			| Disables "X" button in your calendar
 *	disableYearNav			| Disables year navigation buttons
 *	minimal					| Make calendar minimal look (disable everything that can)
 *	theme						| Theme name
 *	showEffect				| Name of the effect that shows calendar
 *	showEffectSpeed		| Speed of the show effect
 *	showEffectOnFinish	| Function that is called when the show effect action is complete
 *	hideEffect				| Name of the effect that hides calendar
 *	hideEffectSpeed		| Speed of the hide effect
 *	hideEffectOnFinish	| Function that is called when the hide effect action is complete
 *	showAfterCreation		| Shows popup calendar when created
 *	maxSelection			| Maximum selected dates that allowing (default: -1 is mean that calendar hasn`t selection limit)
 *	setDateToolTip			| callback function that gets a date and sets tooltip text for this date
 * loadPrefs				| true/false. Loads the preference cookie and merges saved prefs to Zapatec.Calendar.prefs (history)
 *	historySize				| History size
 *	hideNavPanel			| Navigation panel that contains prev/next month/year, today buttons 
 *
 * One of "inputField", "displayArea" or "button" is required.
 *
 * &lt;strong&gt;In addition to the events fired from base Zapatec.Widget class fires
 * the following events:&lt;/strong&gt;
 *
 * &lt;b&gt;calDateClicked&lt;/b&gt; when date is clicked. Listener receives Date object.
 *
 * &lt;b&gt;calDateDblclicked&lt;/b&gt; when date is double clicked. Listener receives Date
 * object.
 *
 * &lt;b&gt;calDateSwitched&lt;/b&gt; when date is set programmatically. Listener receives
 * Date object.
 *
 * &lt;b&gt;calMonthClicked&lt;/b&gt; when month (title) is clicked. Listener receives
 * following object:
 * {
 *   fullYear: [number] full year,
 *   month: [number] zero-based month number (0 - 11)
 * }
 * &lt;/pre&gt;
 *
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@extends</span> Zapatec.Widget
 * <span class="attrib">@requires</span> Zapatec.Widget Requires utils/zapatec.js
 * <span class="attrib">@param</span> {object} oArg User configuration
 */</span>
Zapatec.Calendar = <span class="reserved">function</span>(oArg, date, onSelect, onClose) {
	<span class="comment">// For backward compatibility</span>
	<span class="reserved">if</span> (typeof oArg != <span class="literal">'object'</span>) {
		var firstDay = oArg;
		oArg = {};
		<span class="reserved">if</span> (firstDay != null) oArg.firstDay = firstDay;
		<span class="reserved">if</span> (date) oArg.date = date;
		<span class="reserved">if</span> (onSelect) oArg.onSelect = onSelect;
		<span class="reserved">if</span> (onClose)  oArg.onClose = onClose;
	}
	<span class="comment">// Call constructor of superclass</span>
	zapatecCalendar.SUPERconstructor.call(<span class="reserved">this</span>, oArg);
};

<span class="comment">/**
 * Shortcut for faster access.
 * <span class="attrib">@private</span>
 * <span class="attrib">@final</span>
 */</span>
zapatecCalendar = Zapatec.Calendar;

Zapatec.Calendar.activeCalendar = null;

<span class="comment">/**
 * Unique static id of the calendar class. Gives ability for Zapatec#inherit to
 * determine and store path to this file correctly when it is included using
 * Zapatec#include. When this file is included using Zapatec#include or path
 * to this file is gotten using Zapatec#getPath, this value must be specified
 * as script id.
 * <span class="attrib">@private</span>
 */</span>
Zapatec.Calendar.id = <span class="literal">"Zapatec.Calendar"</span>;

<span class="comment">// Inherit Zapatec Widget</span>
Zapatec.inherit(zapatecCalendar, zapatecWidget);

<span class="comment">/**
 * Initializes object.
 *
 * <span class="attrib">@param</span> {object} oArg User configuration
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.init = <span class="reserved">function</span>(oArg) {
	<span class="comment">// Call init method of superclass</span>
	zapatecCalendar.SUPERclass.init.call(<span class="reserved">this</span>, oArg);

	var oConfig = <span class="reserved">this</span>.config;

	<span class="reserved">this</span>.activeDiv = null;

	<span class="comment">// Create historyDateFormat</span>
	<span class="reserved">this</span>.historyDateFormat = oConfig.ifFormat || oConfig.daFormat || <span class="literal">'%B %d, %Y'</span>;
	<span class="comment">// Other 'private' paramiters</span>
	<span class="reserved">this</span>.currentDateEl = null;
	<span class="reserved">this</span>.getDateStatus = null;
	<span class="reserved">this</span>.getDateToolTip = null;
	<span class="reserved">this</span>.timeout = null;
	<span class="reserved">this</span>.dragging = false;
	<span class="reserved">this</span>.hidden = false;
	<span class="reserved">this</span>.minYear = 1970;
	<span class="reserved">this</span>.maxYear = 2050;
	<span class="reserved">this</span>.minMonth = 0;
	<span class="reserved">this</span>.maxMonth = 11;
	<span class="reserved">this</span>.isPopup = false;
	<span class="reserved">this</span>.hiliteToday = true;
	<span class="comment">// HTML elements</span>
	<span class="reserved">this</span>.table = null;
	<span class="reserved">this</span>.element = null;
	<span class="reserved">this</span>.tbody = [];
	<span class="reserved">this</span>.firstDayName = null;
	<span class="comment">// Combo boxes</span>
	<span class="reserved">this</span>.monthsCombo = null;
	<span class="reserved">this</span>.hilitedMonth = null;
	<span class="reserved">this</span>.activeMonth = null;
	<span class="reserved">this</span>.yearsCombo = null;
	<span class="reserved">this</span>.hilitedYear = null;
	<span class="reserved">this</span>.activeYear = null;
	<span class="reserved">this</span>.histCombo = null;
	<span class="reserved">this</span>.hilitedHist = null;
	<span class="comment">// Information</span>
	<span class="reserved">this</span>.dateClicked = false;
	<span class="reserved">this</span>.titles = [];
	<span class="reserved">this</span>.rowsOfDayNames = [];
	<span class="comment">//Last row hilite object</span>
	<span class="reserved">this</span>.lastRowHilite = null;
	<span class="comment">// Close button object</span>
	<span class="reserved">this</span>.closeButton = null;
	<span class="comment">// Help button object</span>
	<span class="reserved">this</span>.helpButton = null;
	<span class="comment">// Flag for opera</span>
	<span class="comment">//this.justCreate = false;</span>
	<span class="comment">// Save triggerElfor popup</span>
	<span class="reserved">this</span>.triggerEl = null;

	<span class="comment">// Flag to create calendar</span>
	<span class="reserved">if</span> (!<span class="reserved">this</span>.isCreate)
		<span class="reserved">this</span>.isCreate = false;

	<span class="comment">// set tooltips</span>
	<span class="reserved">if</span> (typeof oConfig.setDateToolTip == <span class="literal">"function"</span>)
		<span class="reserved">this</span>.setDateToolTipHandler(oConfig.setDateToolTip);

	<span class="reserved">this</span>.setRange(oConfig.range[0], oConfig.range[1]);

	<span class="comment">// Init data (language and others)</span>
	<span class="comment">//Zapatec.Calendar._initSDN();</span>
	<span class="reserved">if</span> (Zapatec.Langs) {
		<span class="reserved">if</span> (!<span class="reserved">this</span>.langStr)
			<span class="reserved">this</span>.langStr = oConfig.lang;
	}
	<span class="reserved">else</span>
		Zapatec.Calendar._initSDN();

	<span class="reserved">this</span>.dateFormat = Zapatec.Calendar.i18n(<span class="literal">"DEF_DATE_FORMAT"</span>, null, <span class="reserved">this</span>);
	<span class="reserved">this</span>.ttDateFormat = Zapatec.Calendar.i18n(<span class="literal">"TT_DATE_FORMAT"</span>, null, <span class="reserved">this</span>);

	<span class="comment">// Old paramiter dateStr.</span>
	<span class="reserved">this</span>.dateStr = oConfig.date;

	<span class="comment">// Load css, if need</span>
	<span class="reserved">if</span> (oConfig.themeSize.length &gt; 0)
		Zapatec.Transport.loadCss({url : oConfig.themePath + oConfig.themeSize.toLowerCase() + <span class="literal">".css"</span>, async:false});

	<span class="comment">// Init isPopup</span>
	<span class="reserved">if</span> (!oConfig.flat)
		<span class="reserved">this</span>.isPopup = true;

	<span class="comment">// Set onSelect</span>
	<span class="reserved">if</span> (typeof oConfig.onSelect == <span class="literal">"function"</span>) {
		<span class="reserved">this</span>.onSelected = oConfig.onSelect;
	} <span class="reserved">else</span> {
		<span class="reserved">this</span>.onSelected = <span class="reserved">this</span>.onSelectInner;
	}
	<span class="comment">// Set onClose</span>
	<span class="reserved">if</span> (typeof oConfig.onClose != <span class="literal">"function"</span>)
		oConfig.onClose = <span class="reserved">this</span>.onCloseInner;
	<span class="comment">// time24 setup</span>
	<span class="reserved">this</span>.time24 = (oConfig.timeFormat == <span class="literal">'24'</span>);
	<span class="comment">// multiple dates</span>
	<span class="reserved">if</span> (oConfig.multiple) {
		<span class="reserved">this</span>.setMultipleDates(oConfig.multiple);
	}
	<span class="comment">// Setup dateStatus and disableFunc functions</span>
	<span class="reserved">if</span> (typeof oConfig.disableFunc == <span class="literal">'function'</span>)
		<span class="reserved">this</span>.setDisabledHandler(oConfig.disableFunc);
	<span class="reserved">if</span> (typeof oConfig.dateStatusFunc == <span class="literal">'function'</span>)
		<span class="reserved">this</span>.setDateStatusHandler(oConfig.dateStatusFunc);

	<span class="comment">// Convert elements if need</span>
	oConfig.inputField = Zapatec.Widget.getElementById(oConfig.inputField);
	oConfig.displayArea = Zapatec.Widget.getElementById(oConfig.displayArea);
	oConfig.button = Zapatec.Widget.getElementById(oConfig.button);

	<span class="reserved">if</span> (!oConfig.inputField) {
		oConfig.canType = false;
	} <span class="reserved">else</span> {
		oConfig.inputField.setAttribute(<span class="literal">"autocomplete"</span>, <span class="literal">"off"</span>);
	}

	<span class="comment">// Create error object</span>
	var oError = new Object;
	oError.source = <span class="literal">"setup"</span>;
	oError.id = oConfig.id;

	<span class="reserved">if</span> (!(oConfig.flat || oConfig.multiple || oConfig.inputField || oConfig.displayArea || oConfig.button)) {
		oError.errorDescription = <span class="literal">"Nothing to setup (no fields found). Please check your code."</span>;
		<span class="comment">//Zapatec.Calendar.submitErrorFunc(oError);</span>
		<span class="comment">//return false;</span>
	}

	<span class="reserved">if</span> (((oConfig.timeInterval) &amp;&amp; ((oConfig.timeInterval !== Math.floor(oConfig.timeInterval)) || ((60 % oConfig.timeInterval !== 0) &amp;&amp; (oConfig.timeInterval % 60 !== 0)))) || (oConfig.timeInterval &gt; 360)) {
		oError.errorDescription = <span class="literal">"timeInterval option can only have the following number of minutes:\n1, 2, 3, 4, 5, 6, 10, 15, 30,  60, 120, 180, 240, 300, 360 "</span>;
		Zapatec.Calendar.submitErrorFunc(oError);
		oConfig.timeInterval = null;
	}

	<span class="reserved">if</span> (oConfig.date &amp;&amp; !Date.parse(oConfig.date)) {
		oError.errorDescription = <span class="literal">"Start Date Invalid. See date option.\nDefaulting to today."</span>;
		Zapatec.Calendar.submitErrorFunc(oError);
		oConfig.date = null;
	}

	<span class="comment">// Load cookies</span>
	<span class="reserved">this</span>.setCookie();

	<span class="comment">// Set multiple to maxSelected</span>
	<span class="reserved">if</span> (oConfig.multiple &amp;&amp; oConfig.maxSelection &gt; 0 &amp;&amp; <span class="reserved">this</span>._getMultipleLength() &gt; oConfig.maxSelection) {
		<span class="reserved">this</span>._delUnnecessaryMultiple(oConfig.maxSelection);
	}

	<span class="reserved">if</span> (oConfig.flat != null) {
		oConfig.flat = Zapatec.Widget.getElementById(oConfig.flat);

		<span class="reserved">if</span> (!oConfig.flat) {
			Zapatec.Calendar.submitErrorFunc({
				sourse		: <span class="literal">"setup"</span>,
				id				: oConfig.id,
				errorDescription  : <span class="literal">"Flat specified but can't find parent."</span>
			});
			<span class="reserved">return</span> false;
		}

		<span class="reserved">if</span> (oConfig.ifFormat) {
			<span class="reserved">this</span>.setDateFormat(oConfig.ifFormat);
		}

	} <span class="reserved">else</span>
		<span class="reserved">if</span> (oConfig.canType) {
			Zapatec.Utils.addEvent(oConfig.inputField, <span class="literal">"mousedown"</span>, Zapatec.Calendar.cancelBubble);
			Zapatec.Utils.addEvent(oConfig.inputField, <span class="literal">"keydown"</span>, Zapatec.Calendar.cancelBubble);
			Zapatec.Utils.addEvent(oConfig.inputField, <span class="literal">"keypress"</span>, Zapatec.Calendar.cancelBubble);
			Zapatec.Utils.addEvent(oConfig.inputField, <span class="literal">"keyup"</span>, <span class="reserved">function</span>(ev) {
				var cal = Zapatec.Calendar.activeCalendar;
				var format = oConfig.inputField ? oConfig.ifFormat : oConfig.daFormat;
				var parsedDate = zapatecDate.parseDate.call(<span class="reserved">this</span>, oConfig.inputField.value, format);
				<span class="reserved">if</span> (parsedDate &amp;&amp; !cal.hidden) {
					<span class="reserved">if</span> (cal.setDate(parsedDate)) {
						cal.showHint(Zapatec.Calendar.i18n(<span class="literal">"SEL_DATE"</span>, null, cal));
					}
				}
			});
			Zapatec.Utils.addEvent(oConfig.inputField, <span class="literal">"blur"</span>, <span class="reserved">function</span>(ev) {
				var cal = Zapatec.Calendar.activeCalendar;
				var format = oConfig.inputField ? oConfig.ifFormat : oConfig.daFormat;
				var parsedDate = zapatecDate.parseDate.call(<span class="reserved">this</span>, oConfig.inputField.value, format);
				<span class="reserved">if</span> (!parsedDate) {
					oConfig.inputField.value = cal.printWith2Time(cal.currentDate, cal.currentDateEnd, format);
				}
			});
		}

	<span class="comment">// Setup events</span>
	var triggerEl = oConfig.button || oConfig.displayArea || oConfig.inputField;

	<span class="reserved">if</span> (triggerEl) {
		<span class="comment">// Fix for Zapatec.Calendar.setup</span>
		<span class="comment">//var triggerEl = oConfig.button || oConfig.displayArea || oConfig.inputField;</span>
		var widget = {};
		<span class="reserved">for</span> (i = 0; i &lt; Zapatec.Widget.all.length - 1; i++)
			<span class="reserved">if</span> (Zapatec.Widget.all[i] instanceof Zapatec.Calendar) {
				<span class="reserved">if</span> (oConfig.inputField)  widget = Zapatec.Widget.all[i].config.inputField;
				<span class="reserved">if</span> (oConfig.displayArea) widget = Zapatec.Widget.all[i].config.displayArea;
				<span class="reserved">if</span> (oConfig.button)	 widget = Zapatec.Widget.all[i].config.button;

				<span class="reserved">if</span> (widget == triggerEl) {
					Zapatec.Widget.all[i].destroy();
				}
			}
		<span class="comment">// End fix</span>
		var selfEff = <span class="reserved">this</span>.config.showEffectOnFinish;
		<span class="reserved">this</span>.triggerEl = triggerEl;
		<span class="reserved">this</span>.config.showEffectOnFinish = <span class="reserved">function</span> () {
			<span class="reserved">if</span> (<span class="literal">"function"</span> == typeof selfEff) {
				selfEff();
			}
			triggerEl.disabled = false;
		}
		Zapatec.Utils.addEvent(triggerEl, oConfig.eventName, new Function(<span class="literal">"Zapatec.Widget.getWidgetById("</span> + <span class="reserved">this</span>.id + <span class="literal">").unHide(this)"</span>));
	}


	<span class="reserved">if</span> (oConfig.closeEventName &amp;&amp; !Zapatec.is_opera) {
		Zapatec.Utils.addEvent(triggerEl, oConfig.closeEventName, new Function(<span class="literal">"Zapatec.Widget.getWidgetById("</span> + <span class="reserved">this</span>.id + <span class="literal">").callCloseHandler()"</span>));
	}

	<span class="comment">/* If Zapatec.Effects not included to the script - include it.
	 * This prevent "firsttime blinking" of the calendar, when load / reload page.
	 */</span>
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.showEffect.length &gt; 0 &amp;&amp; typeof(Zapatec.Effects) == <span class="literal">'undefined'</span>) {
		<span class="reserved">this</span>.container = new Object; <span class="comment">// set container to not null</span>
		<span class="reserved">this</span>.showContainer(<span class="reserved">this</span>.config.showEffect, <span class="reserved">this</span>.config.showEffectSpeed, <span class="reserved">this</span>.config.showEffectOnFinish);
	}

	<span class="comment">// set the calendar close button</span>
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.closeButton) {
		var cal = <span class="reserved">this</span>;
		<span class="reserved">this</span>.closeButton = new Zapatec.Button(<span class="reserved">this</span>.config.closeButton);
		<span class="reserved">this</span>.closeButton.config.clickAction = <span class="reserved">function</span>() {
			<span class="reserved">if</span> (typeof cal.config.closeButton[<span class="literal">'clickAction'</span>] == <span class="literal">'function'</span>) {
				cal.config.closeButton[<span class="literal">'clickAction'</span>]();
			}
			cal.callCloseHandler();
		};
	}
	<span class="comment">// set the calendar help button</span>
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.helpButton) {
		var cal = <span class="reserved">this</span>;
		<span class="reserved">this</span>.helpButton = new Zapatec.Button(<span class="reserved">this</span>.config.closeButton);
		<span class="reserved">this</span>.helpButton.config.clickAction = <span class="reserved">function</span>() {
			<span class="reserved">if</span> (typeof cal.config.helpButton[<span class="literal">'clickAction'</span>] == <span class="literal">'function'</span>) {
				cal.config.helpButton[<span class="literal">'clickAction'</span>]();
			}
			cal.callHelpHandler();
		};
	}

	<span class="comment">// Define conainer of Calendar</span>
	<span class="reserved">this</span>.container = oConfig.flat || <span class="reserved">this</span>.element;

	<span class="reserved">if</span> (!<span class="reserved">this</span>.isPopup) {
		Zapatec.Calendar.activeCalendar = <span class="reserved">this</span>;
		<span class="reserved">this</span>.create(oConfig.flat);
		<span class="reserved">if</span> (oConfig.inputField &amp;&amp; oConfig.inputField.type == <span class="literal">"text"</span> &amp;&amp; typeof oConfig.inputField.value == <span class="literal">"string"</span>) {
			<span class="reserved">this</span>.parseDate(oConfig.inputField.value);
		}
		<span class="reserved">this</span>.show();
	} <span class="reserved">else</span> <span class="reserved">if</span> (oConfig.showAfterCreation) {
		<span class="reserved">this</span>.unHide(triggerEl);
	}
};

<span class="comment">/**
 * Reconfigures the calendar with new config options after it was initialized.
 * May be used to change look or behavior of the calendar.
 * In the argument pass only values for changed config options.
 * There is no need to pass config options that were not changed.
 *
 * &lt;pre&gt;
 *
 *
 * &lt;/pre&gt;
 *
 * <span class="attrib">@param</span> {object} oArg Changes to user configuration
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.reconfigure = <span class="reserved">function</span>(oArg) {
	<span class="comment">// Call parent method</span>
	zapatecCalendar.SUPERclass.reconfigure.call(<span class="reserved">this</span>, oArg);
	<span class="reserved">this</span>.show();
};

<span class="comment">/**
 * Configures calendar. Gets called from parent init method.
 *
 * <span class="attrib">@private</span>
 * <span class="attrib">@param</span> {object} oArg User configuration
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.configure = <span class="reserved">function</span>(oArg) {

	<span class="comment">// Define config options</span>
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'inputField'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'displayArea'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'button'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'eventName'</span>, <span class="literal">'click'</span>);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'closeEventName'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'ifFormat'</span>, <span class="literal">'%Y/%m/%d'</span>);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'daFormat'</span>, <span class="literal">'%Y/%m/%d'</span>);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'singleClick'</span>, true);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'disableFunc'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'dateStatusFunc'</span>, oArg.disableFunc ? oArg.disableFunc : null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'dateText'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'firstDay'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'align'</span>, <span class="literal">'Br'</span>);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'range'</span>, [1900, 2999]);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'weekNumbers'</span>, true);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'flat'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'flatCallback'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'onSelect'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'onClose'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'onUpdate'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'onFDOW'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'noGrab'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'date'</span>, <span class="literal">''</span>);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'dateEnd'</span>, <span class="literal">''</span>);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'showsTime'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'sortOrder'</span>, <span class="literal">'asc'</span>);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'timeFormat'</span>, <span class="literal">'24'</span>);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'timeInterval'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'electric'</span>, true);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'step'</span>, 2);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'position'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'cache'</span>, true);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'showOthers'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'multiple'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'multipleRange'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'multipleSelection'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'saveDate'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'fdowClick'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'titleHtml'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'noHelp'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'noCloseButton'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'disableYearNav'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'disableFdowChange'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'multiple'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'disableDrag'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'numberMonths'</span>, 1);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'stepMonths'</span>);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'monthsInRow'</span>, oArg.numberMonths ? oArg.numberMonths : 1);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'controlMonth'</span>, 1);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'vertical'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'canType'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'theme'</span>, <span class="literal">'bluexp'</span>);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'themeSize'</span>, <span class="literal">''</span>);
	<span class="reserved">if</span> (Zapatec.Langs) {
		<span class="reserved">this</span>.defineConfigOption(<span class="literal">'langId'</span>, Zapatec.Calendar.id);
		<span class="reserved">this</span>.defineConfigOption(<span class="literal">'lang'</span>, <span class="literal">'en'</span>);
	}
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'showEffect'</span>, <span class="literal">''</span>);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'showEffectSpeed'</span>, 100);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'showEffectOnFinish'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'hideEffect'</span>, <span class="literal">''</span>);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'hideEffectSpeed'</span>, 100);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'hideEffectOnFinish'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'showAfterCreation'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'noHistory'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'noStatus'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'minimal'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'maxSelection'</span>, -1);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'onWeekClick'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'onTodayClick'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'onMonthSelect'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'onYearSelect'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'onHistorySelect'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'setDateToolTip'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'timeRange'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'onCreate'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'closeButton'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'helpButton'</span>, null);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'loadPrefs'</span>, false);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'historySize'</span>, 9);
	<span class="reserved">this</span>.defineConfigOption(<span class="literal">'hideNavPanel'</span>, false);

	<span class="comment">// Call parent method</span>
	zapatecCalendar.SUPERclass.configure.call(<span class="reserved">this</span>, oArg);

	var oConfig = <span class="reserved">this</span>.config;

	<span class="comment">// preferences</span>
	<span class="reserved">if</span> (!oConfig.prefs)
		oConfig.prefs = {
			fdow		: null,					 <span class="comment">/**&lt; when NULL we will use the user options  */</span>
			history	: <span class="literal">""</span>,						 <span class="comment">/**&lt; keeps the history as one big string */</span>
			hsize		: oConfig.historySize <span class="comment">/**&lt; maximum history size (number of stored items) */</span>
		};

	<span class="comment">// initialize the preferences object;</span>
	<span class="reserved">if</span> (oConfig.loadPrefs) {
		Zapatec.Calendar.loadPrefs(oConfig);
	}

	<span class="comment">// Load size css (hiude/big/small/tiny)</span>
	oConfig.themeSize = oConfig.themeSize.toLowerCase();
	<span class="reserved">if</span> (oConfig.themeSize == <span class="literal">'normal'</span>)
		oConfig.themeSize = <span class="literal">''</span>;
	var firstLetter = oConfig.themeSize.substr(0, 1);
	oConfig.themeSize = firstLetter.toUpperCase() + oConfig.themeSize.substr(1);

	<span class="reserved">if</span> (oConfig.prefs.fdow || (oConfig.prefs.fdow == 0)) {
		oConfig.firstDay = parseInt(oConfig.prefs.fdow, 10);
	} <span class="reserved">else</span> {
		var fd = 1;
		<span class="reserved">if</span> (typeof oConfig.firstDay == <span class="literal">"number"</span>) {
			fd = oConfig.firstDay;
		} <span class="reserved">else</span> <span class="reserved">if</span> (typeof <span class="reserved">this</span>._FD == <span class="literal">'number'</span>) {
			fd = <span class="reserved">this</span>._FD;
		}
		oConfig.firstDay = fd;
	}

	<span class="comment">//---------- Change paramiters acording to the conditions</span>
	<span class="reserved">if</span> (oConfig.weekNumbers) {
		oConfig.disableFdowChange = true;
	} <span class="reserved">else</span> {
		oConfig.onWeekClick = null;
	}

	<span class="comment">// numberMonth condition</span>
	<span class="reserved">if</span> ((oConfig.numberMonths &gt; 12) || (oConfig.numberMonths &lt; 1)) {
		oConfig.numberMonths = 1;
	}
	oConfig.numberMonths = parseInt(oConfig.numberMonths, 10);
	<span class="comment">// stepMonths</span>
	oConfig.stepMonths = parseInt(oConfig.stepMonths);
	<span class="reserved">if</span> (isNaN(oConfig.stepMonths) || oConfig.stepMonths &lt; 1) {
		oConfig.stepMonths = oConfig.numberMonths;
	}

	<span class="comment">// controlMonth condition</span>
	<span class="reserved">if</span> ((oConfig.controlMonth &gt; oConfig.numberMonths) || (oConfig.controlMonth &lt; 1)) {
		oConfig.controlMonth = 1;
	}
	oConfig.controlMonth = parseInt(oConfig.controlMonth, 10);

	<span class="comment">// monthsInRow</span>
	<span class="reserved">if</span> (oConfig.monthsInRow &gt; oConfig.numberMonths) {
		oConfig.monthsInRow = oConfig.numberMonths;
	}
	oConfig.monthsInRow = parseInt(oConfig.monthsInRow, 10);

	<span class="comment">// Set multiple dates</span>
	<span class="reserved">if</span> (oConfig.multipleSelection &amp;&amp; ! oConfig.multiple) {
		oConfig.multiple = [];
	}
	<span class="reserved">if</span> (oConfig.multiple &amp;&amp; !oConfig.multipleSelection) {
		oConfig.multipleSelection = true;
	}
	<span class="comment">// Multiple range works only with multiple</span>
	<span class="reserved">if</span> (oConfig.multipleRange &amp;&amp; !oConfig.multiple) {
		oConfig.multipleRange = null;
	}

	<span class="comment">// singleClick</span>
	<span class="reserved">if</span> (oConfig.multiple) {
		oConfig.singleClick = false;
	}

	oConfig.sortOrder = oConfig.sortOrder.toLowerCase();

	<span class="comment">// Animation speed</span>
	oConfig.showEffectSpeed = parseInt(oConfig.showEffectSpeed, 10);
	oConfig.hideEffectSpeed = parseInt(oConfig.hideEffectSpeed, 10);

	<span class="comment">// Calendar with time range</span>
	<span class="reserved">if</span> (oConfig.multipleRange &amp;&amp; !oConfig.timeRange) {
		oConfig.timeRange = true;
	}

	<span class="reserved">if</span> (oConfig.timeRange &amp;&amp; !oConfig.showsTime) {
		oConfig.showsTime = true;
	}

	<span class="comment">// Minmal calendar</span>
	<span class="reserved">if</span> (oConfig.minimal) {
		oConfig.noHelp = true;
		oConfig.noCloseButton = true;
		oConfig.noHistory = true;
		oConfig.noStatus = true;
		oConfig.disableYearNav = true;
		oConfig.disableFdowChange = true;
		oConfig.weekNumbers = false;
		oConfig.fdowClick = false;
		oConfig.showsTime = false;
		oConfig.timeRange = false;
	}

	<span class="comment">// Setup buttons</span>
	<span class="reserved">if</span> (oConfig.noCloseButton || !Zapatec.Button) {
		oConfig.closeButton = null;
	}
	<span class="reserved">if</span> (oConfig.noHelp || !Zapatec.Button) {
		oConfig.helpButton = null;
	}
	<span class="reserved">if</span> (oConfig.hideNavPanel) {
		oConfig.minimal = true;
	}
};

<span class="comment">/**
 * Show popup calendar.
 * Yes, yes I know, but function "show" already included in prototype!
 * <span class="attrib">@private</span> (use option showAfterCreation or emulate button press)
 *
 * <span class="attrib">@param</span> triggerEl - html element that show calendar
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.unHide = <span class="reserved">function</span> (triggerEl) {
	var cal = <span class="reserved">this</span>;
	cal.lastRowHilite = null;
	<span class="reserved">if</span> (!cal)
		<span class="reserved">return</span>;


	<span class="comment">// Call reinit for set init data of the calendar (if no reinit must call from the button.onClick handler)</span>
	<span class="reserved">if</span> (!cal.isCreate) {
		<span class="reserved">if</span> (cal.config.date &amp;&amp; cal.config.cache)
			cal.setDate(cal.config.date);
		cal.create(cal.config.flat);
	} <span class="reserved">else</span> {
		<span class="reserved">if</span> (cal.config.date &amp;&amp; cal.config.cache)
			cal.setDate(cal.config.date);
		cal.reconfigure(cal.config);
		cal.reinit();
	}

	var oConfig = cal.config;
	var dateEl = oConfig.inputField || oConfig.displayArea;
	<span class="comment">//FIX for Enter key!  But do not work in IE!</span>
	<span class="reserved">if</span> (!Zapatec.is_ie &amp;&amp; (!oConfig.canType || oConfig.inputField != triggerEl) &amp;&amp; triggerEl.blur) {
		triggerEl.blur();
	}

	var dateFmt = oConfig.inputField ? oConfig.ifFormat : oConfig.daFormat;

	<span class="reserved">if</span> (oConfig.canType &amp;&amp; (oConfig.inputField == triggerEl) &amp;&amp; cal &amp;&amp; !cal.hidden) {
		<span class="comment">//return;</span>
	}

	<span class="reserved">if</span> (dateEl) {
		var dateValue;
		<span class="comment">//figure out if the it's in value or innerHTML</span>
		<span class="reserved">if</span> (dateEl.value) {
			dateValue = dateEl.value;
		} <span class="reserved">else</span> {
			dateValue = dateEl.innerHTML;
		}
		<span class="reserved">if</span> (dateValue != <span class="literal">""</span>) { <span class="comment">//if there is a date to initialize from</span>
			<span class="comment">// Need translator for parseDate</span>
			Zapatec.Calendar.activeCalendar = <span class="reserved">this</span>;
			var parsedDate = zapatecDate.parseDate.call(<span class="reserved">this</span>, dateEl.value || dateEl.innerHTML, dateFmt);
			<span class="comment">//This check for when webmaster initializes the box with something like</span>
			<span class="comment">//"check in"</span>
			<span class="reserved">if</span> (parsedDate != null) { <span class="comment">//if it's parsable</span>
				<span class="reserved">if</span> (!(typeof cal.config.dateStatusFunc == <span class="literal">"function"</span> &amp;&amp; cal.config.dateStatusFunc(parsedDate)) &amp;&amp; !cal.setDate(parsedDate))
					oConfig.inputField.value = cal.printWith2Time(cal.currentDate, cal.currentDateEnd, cal.config.ifFormat);
			}
			<span class="reserved">else</span>
				oConfig.inputField.value = cal.printWith2Time(cal.currentDate, cal.currentDateEnd, cal.config.ifFormat);
		}
	}

	<span class="comment">// Disable trigger element</span>
	<span class="reserved">if</span> (triggerEl) {
		triggerEl.disabled = true;
	}
	<span class="reserved">if</span> (!oConfig.position)
		cal.showAtElement(oConfig.button || oConfig.displayArea || oConfig.inputField, oConfig.align);
	<span class="reserved">else</span>
		cal.showAt(oConfig.position[0], oConfig.position[1]);

	<span class="reserved">return</span> false;
};

<span class="comment">/**
 * Set cookie, if it was saved.
 * no paramiters
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.setCookie = <span class="reserved">function</span>() {
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.saveDate) { <span class="comment">//If saveDate is on We're saving the date in a cookie</span>
		<span class="reserved">this</span>.cookiePrefix = window.location.href + <span class="literal">"--"</span> + <span class="reserved">this</span>.config.button.id
		<span class="comment">//fetch the cookie</span>
		var cookieName = <span class="reserved">this</span>.cookiePrefix;
		var newdate = Zapatec.Utils.getCookie(cookieName);
		<span class="reserved">if</span> (newdate != null) {
			<span class="comment">//if there's a cookie</span>
			<span class="comment">//set the value of the text field</span>
			Zapatec.Widget.getElementById(<span class="reserved">this</span>.config.inputField.id).value = newdate;
		}
	}
};


<span class="comment">/**
 * Get length of multiple collection
 * <span class="attrib">@private</span>
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>._getMultipleLength = <span class="reserved">function</span> () {
	var counter = 0;
	<span class="reserved">for</span> (var item in <span class="reserved">this</span>.config.multiple) {
		counter++;
	}

	<span class="reserved">return</span> counter;
}

<span class="comment">/**
 * Delete unnecessary multiple dates
 *
 * <span class="attrib">@private</span>
 * <span class="attrib">@param</span> {integer} number - number of max multiple length (i.e. maxSelected)
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>._delUnnecessaryMultiple = <span class="reserved">function</span> (number) {
	var cal = <span class="reserved">this</span>;
	var counter = 1;
	<span class="reserved">if</span> (number &gt; 0 &amp;&amp; cal._getMultipleLength() &gt; number) {
		<span class="reserved">for</span> (var item in cal.config.multiple) {
			<span class="reserved">if</span> (counter++ &gt; number) {
				delete cal.config.multiple[item];
			}
		}
	}
}
<span class="comment">/**
 * Default onSelect function
 * <span class="attrib">@private</span>
 *
 * <span class="attrib">@cal</span> - calendar
 * <span class="attrib">@date</span> - starting date
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.onSelectInner = <span class="reserved">function</span>(cal, date) {
	var p = cal.config;
	<span class="comment">// For old version support</span>
	<span class="reserved">for</span> (var prop in p) {
		cal[prop] = p[prop];
	}
	<span class="comment">// end support</span>

	var update = (cal.dateClicked || p.electric);
	<span class="reserved">if</span> (update &amp;&amp; p.flat) {
		<span class="reserved">if</span> (typeof p.flatCallback == <span class="literal">"function"</span>) {
			<span class="reserved">if</span> (!p.multiple) {
				<span class="comment">//User can call function submitFlatDates directly in Calendar object to handle the submission of multiple dates.</span>
				p.flatCallback(cal);
			}
		}
		<span class="reserved">return</span> false;
	}
	<span class="reserved">if</span> (update &amp;&amp; p.inputField) {
		p.inputField.value = <span class="reserved">this</span>.printWith2Time(cal.currentDate, cal.currentDateEnd, p.ifFormat);
		<span class="reserved">if</span> (typeof p.inputField.onchange == <span class="literal">"function"</span>)
			p.inputField.onchange();
	}
	<span class="reserved">if</span> (update &amp;&amp; p.displayArea) {
		p.displayArea.innerHTML = <span class="reserved">this</span>.printWith2Time(cal.currentDate, cal.currentDateEnd, p.daFormat);
	}
	<span class="reserved">if</span> (update &amp;&amp; p.singleClick &amp;&amp; cal.dateClicked) {
		cal.callCloseHandler();
	}
	<span class="reserved">if</span> (update &amp;&amp; typeof p.onUpdate == <span class="literal">"function"</span>)
		p.onUpdate(cal);

	<span class="reserved">if</span> (p.saveDate) { <span class="comment">//save date in cookie</span>
		<span class="comment">//unique name of the cookie is the name of the button  + href</span>
		var cookieName = <span class="reserved">this</span>.cookiePrefix;
		Zapatec.Utils.writeCookie(cookieName, p.inputField.value, null, <span class="literal">'/'</span>, p.saveDate);
	}
};

<span class="comment">/**
 * Default onClose function
 * <span class="attrib">@cal</span> - calendar
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.onCloseInner = <span class="reserved">function</span>(cal) {
	<span class="reserved">if</span> (!cal.config.flat)
		cal.hide();
};

<span class="comment">// BEGIN: CALENDAR STATIC FUNCTIONS</span>
<span class="comment">/**
 * Prevent wrong behaviour for typing in the input field
 *
 * <span class="attrib">@private</span>
 * <span class="attrib">@param</span> event - event that occures
 */</span>
Zapatec.Calendar.cancelBubble = <span class="reserved">function</span> (event) {
	event = event || window.event;
	<span class="reserved">if</span> (Zapatec.is_ie) {
		event.cancelBubble = true;
	} <span class="reserved">else</span> {
		event.stopPropagation();
	}
};

<span class="comment">/**
 * \internal This function is called from the constructor, only once, to
 * initialize some internal arrays containing translation strings.  It is also
 * called from the calendar wizard in order to reconfigure the calendar with a
 * language different than the initially selected one.
 *
 * Only for old version
 * <span class="attrib">@private</span>
 */</span>
Zapatec.Calendar._initSDN = <span class="reserved">function</span>() {
	<span class="reserved">if</span> (typeof Zapatec.Calendar._TT == <span class="literal">"undefined"</span>) {
		Zapatec.Calendar._TT = {};
	}

	<span class="reserved">if</span> (typeof Zapatec.Calendar._TT._SDN == <span class="literal">"undefined"</span>) {
		<span class="comment">// table of short day names</span>
		<span class="reserved">if</span> (typeof Zapatec.Calendar._TT._SDN_len == <span class="literal">"undefined"</span>)
			Zapatec.Calendar._TT._SDN_len = 3;
		var ar = [];
		<span class="reserved">for</span> (var i = 8; i &gt; 0;) {
			<span class="reserved">if</span> (Zapatec.Calendar._TT._DN)
				ar[--i] = Zapatec.Calendar._TT._DN[i].substr(0, Zapatec.Calendar._TT._SDN_len);
			<span class="reserved">else</span>
				ar[--i] = <span class="literal">""</span>;
		}
		Zapatec.Calendar._TT._SDN = ar;
		<span class="comment">// table of short month names</span>
		<span class="reserved">if</span> (typeof Zapatec.Calendar._TT._SMN_len == <span class="literal">"undefined"</span>)
			Zapatec.Calendar._TT._SMN_len = 3;
		ar = [];
		<span class="reserved">for</span> (var i = 12; i &gt; 0;) {
			<span class="reserved">if</span> (Zapatec.Calendar._TT._MN)
				ar[--i] = Zapatec.Calendar._TT._MN[i].substr(0, Zapatec.Calendar._TT._SMN_len);
			<span class="reserved">else</span>
				ar[--i] = <span class="literal">""</span>;
		}
		Zapatec.Calendar._TT._SMN = ar;
	}
	<span class="reserved">if</span> (typeof Zapatec.Calendar._TT._AMPM == <span class="literal">"undefined"</span>) {
		Zapatec.Calendar._TT._AMPM = {am : <span class="literal">"am"</span>, pm : <span class="literal">"pm"</span>};
	}
};

<span class="comment">/**
 * Translate a string according to the currently loaded language table.  The
 * \em type variable can be null or missing, or can have one of the following
 * values: "dn", "sdn", "mn", "smn".
 *
 * -# if \em type is null or missing, the given \em str will be looked up in
 *	 the translation table.  If a value is found, it is returned.  Otherwise,
 *	 the string is looked up in the English table (if present).  If still not
 *	 found, the value of \em str itself is returned.
 * -# if \em type is passed, then the value of \em str is looked up in one of
 *	 the following internal arrays, depending on the value of \em type:
 *		 - DN (day name)
 *		 - SDN (short day name)
 *		 - MN (month name)
 *		 - SMN (short month name)
 *
 * <span class="attrib">@param</span> str [string] ID of translation text (can be the English text)
 * <span class="attrib">@param</span> type [string, optional] domain to search through
 *
 * <span class="attrib">@return</span> the translation according to the current language.
 */</span>
Zapatec.Calendar.i18nOld = <span class="reserved">function</span>(str, type) {
	var tr = <span class="literal">''</span>;
	<span class="reserved">if</span> (!Zapatec.Calendar._TT) {
		Zapatec.Calendar._initSDN();
	}
	<span class="reserved">if</span> (!type) {
		<span class="comment">// normal _TT request</span>
		<span class="reserved">if</span> (Zapatec.Calendar._TT) {
			tr = Zapatec.Calendar._TT[str];
		}
		<span class="reserved">if</span> (!tr &amp;&amp; Zapatec.Calendar._TT_en) {
			tr = Zapatec.Calendar._TT_en[str];
		}
	} <span class="reserved">else</span> switch (type) {
		case <span class="literal">"dn"</span>	: <span class="reserved">if</span> (Zapatec.Calendar._TT._DN) tr = Zapatec.Calendar._TT._DN[str];  break;
		case <span class="literal">"sdn"</span>	: <span class="reserved">if</span> (Zapatec.Calendar._TT._SDN) tr = Zapatec.Calendar._TT._SDN[str]; break;
		case <span class="literal">"mn"</span>	: <span class="reserved">if</span> (Zapatec.Calendar._TT._MN) tr = Zapatec.Calendar._TT._MN[str];  break;
		case <span class="literal">"smn"</span>	: <span class="reserved">if</span> (Zapatec.Calendar._TT._SMN) tr = Zapatec.Calendar._TT._SMN[str]; break;
		case <span class="literal">"ampm"</span>	: <span class="reserved">if</span> (Zapatec.Calendar._TT._AMPM) tr = Zapatec.Calendar._TT._AMPM[str]; break;
	}
	<span class="reserved">if</span> (!tr) {
		tr = <span class="literal">""</span> + str;
	}

	<span class="reserved">return</span> tr;
};

<span class="comment">/**
 * Function called by Zapatec.Date object.
 * It call Zapatec.Calendar.i18nOld for old version of calendar or correct value from new translation engine.
 *
 * <span class="attrib">@private</span>
 * <span class="attrib">@param</span> str [string] ID of translation text (can be the English text)
 * <span class="attrib">@param</span> type [string, optional] domain to search through
 *
 * <span class="attrib">@return</span> the translation according to the current language.
 */</span>
Zapatec.Calendar.i18n = <span class="reserved">function</span>(str, type, calendar) {
	var newType = <span class="literal">""</span>;
	var cal = null;
	<span class="reserved">if</span> (typeof calendar == <span class="literal">'undefined'</span>) {
		cal = Zapatec.Calendar.activeCalendar;
	} <span class="reserved">else</span> {
		cal = calendar;
	}

	<span class="reserved">if</span> (cal != null &amp;&amp; Zapatec.Langs &amp;&amp; Zapatec.Langs[<span class="literal">"Zapatec.Calendar"</span>]) {
		<span class="reserved">if</span> (typeof type != <span class="literal">'undefined'</span> &amp;&amp; type) {
			newType = <span class="literal">"_"</span> + type.toUpperCase();
			<span class="reserved">return</span> cal.getMessage(newType)[str];
		} <span class="reserved">else</span> {
			<span class="reserved">return</span> cal.getMessage(str);
		}
	}
	<span class="comment">// Old engine</span>
	<span class="reserved">return</span> Zapatec.Calendar.i18nOld(str, type);
};


<span class="comment">/**
 * Writes the preferences cookie.
 *
 * <span class="attrib">@param</span> calendarId the calendar id
 */</span>
Zapatec.Calendar.savePrefs = <span class="reserved">function</span>(calendarId) {
	<span class="comment">// FIXME: should we make the domain, path and expiration time configurable?</span>
	<span class="comment">// I guess these defaults are right though..</span>
	var cal = Zapatec.Widget.getWidgetById(calendarId);
	Zapatec.Utils.writeCookie(<span class="literal">"ZP_CAL"</span>, Zapatec.Utils.makePref(cal.config.prefs), null, <span class="literal">'/'</span>, 30);
};

<span class="comment">/**
 * Loads the preference cookie and merges saved prefs to Zapatec.Calendar.prefs.
 */</span>
Zapatec.Calendar.loadPrefs = <span class="reserved">function</span> (oConfig) {
	var txt = Zapatec.Utils.getCookie(<span class="literal">"ZP_CAL"</span>), tmp;
	<span class="reserved">if</span> (txt) {
		tmp = Zapatec.Utils.loadPref(txt);
		<span class="reserved">if</span> (tmp) {
			Zapatec.Utils.mergeObjects(oConfig.prefs, tmp);
		}
	}
	<span class="comment">// FIXME: DEBUG!</span>
	<span class="comment">//this.prefs.history = "1979/03/08,1976/12/28,1978/08/31,1998/09/21";</span>
	<span class="comment">//this.prefs.history = null;</span>
};

<span class="comment">/**
 * \internal Adds a set of events to make some element behave like a button.
 *
 * <span class="attrib">@param</span> el [HTMLElement] reference to your element.
 */</span>
Zapatec.Calendar._add_evs = <span class="reserved">function</span>(el) {
	var C = Zapatec.Calendar;
	el.onmouseover = C.dayMouseOver;
	el.onmousedown = C.dayMouseDown;
	el.onmouseout = C.dayMouseOut;
	el.ondblclick = C.dayMouseDblClick;
};

<span class="comment">/**
 * \internal This function undoes what Zapatec.Calendar._add_evs did, therefore
 * unregisters the event handlers.
 *
 * <span class="attrib">@param</span> el [HTMLElement] reference to your element.
 */</span>
Zapatec.Calendar._del_evs = <span class="reserved">function</span>(el) {
	<span class="reserved">if</span> (!el) {
		<span class="reserved">return</span> null;
	}
	el.onmouseover = null;
	el.onmousedown = null;
	el.onmouseout = null;
	<span class="reserved">if</span> (Zapatec.is_ie) {
		el.ondblclick = null;
	}
};

<span class="comment">/**
 * Given an HTML element, this function determines if it's part of the "months"
 * combo box and if so it returns the element containing the month name.
 *
 * <span class="attrib">@param</span> el [HTMLElement] some element (usually that triggered onclick)
 * <span class="attrib">@return</span> [HTMLElement] element with the month
 */</span>
Zapatec.Calendar.findMonth = <span class="reserved">function</span>(el) {
	<span class="reserved">if</span> (!el) {
		<span class="reserved">return</span> null;
	}
	<span class="reserved">if</span> (typeof el.month != <span class="literal">"undefined"</span>) {
		<span class="reserved">return</span> el;
	} <span class="reserved">else</span> <span class="reserved">if</span> (el.parentNode &amp;&amp; typeof el.parentNode.month != <span class="literal">"undefined"</span>) {
		<span class="reserved">return</span> el.parentNode;
	}

	<span class="reserved">return</span> null;
};

<span class="comment">/** 
 * Similar to findMonth() but for the history combo. 
 */</span>
Zapatec.Calendar.findHist = <span class="reserved">function</span>(el) {
	<span class="reserved">if</span> (!el) {
		<span class="reserved">return</span> null;
	}
	<span class="reserved">if</span> (typeof el.histDate != <span class="literal">"undefined"</span>) {
		<span class="reserved">return</span> el;
	} <span class="reserved">else</span> <span class="reserved">if</span> (el.parentNode &amp;&amp; typeof el.parentNode.histDate != <span class="literal">"undefined"</span>) {
		<span class="reserved">return</span> el.parentNode;
	}

	<span class="reserved">return</span> null;
};

<span class="comment">/** 
 * Similar to the above functions, but for the years combo. 
 */</span>
Zapatec.Calendar.findYear = <span class="reserved">function</span>(el) {
	<span class="reserved">if</span> (!el) {
		<span class="reserved">return</span> null;
	}
	<span class="reserved">if</span> (typeof el.year != <span class="literal">"undefined"</span>) {
		<span class="reserved">return</span> el;
	} <span class="reserved">else</span> <span class="reserved">if</span> (el.parentNode &amp;&amp; typeof el.parentNode.year != <span class="literal">"undefined"</span>) {
		<span class="reserved">return</span> el.parentNode;
	}

	<span class="reserved">return</span> null;
};

<span class="comment">/**
 * This function displays the months combo box.  It doesn't need any parameters
 * because it uses the static activeCalendar variable which maintains a reference to the
 * last calendar that was clicked in the page.
 */</span>
Zapatec.Calendar.showMonthsCombo = <span class="reserved">function</span> () {
	var cal = Zapatec.Calendar.activeCalendar;
	<span class="reserved">if</span> (!cal) {
		<span class="reserved">return</span> false;
	}
	var cd = cal.activeDiv;
	var mc = cal.monthsCombo;

	var date = cal.config.date,
		MM = cal.config.date.getMonth(),
		YY = cal.config.date.getFullYear(),
		min = (YY == cal.minYear),
		max = (YY == cal.maxYear);
	<span class="reserved">for</span> (var i = mc.firstChild; i; i = i.nextSibling) {
		var m = i.month;
		Zapatec.Utils.removeClass(i, <span class="literal">"hilite"</span>);
		Zapatec.Utils.removeClass(i, <span class="literal">"active"</span>);
		Zapatec.Utils.removeClass(i, <span class="literal">"disabled"</span>);
		i.disabled = false;
		<span class="reserved">if</span> ((min &amp;&amp; m &lt; cal.minMonth) ||
			 (max &amp;&amp; m &gt; cal.maxMonth)) {
			Zapatec.Utils.addClass(i, <span class="literal">"disabled"</span>);
			i.disabled = true;
		}
		<span class="reserved">if</span> (m == MM)
			Zapatec.Utils.addClass(cal.activeMonth = i, <span class="literal">"active"</span>);
	}
	var oOffset = zapatecUtils.getElementOffsetRelative(cd);
	var s = mc.style;
	s.display = <span class="literal">"block"</span>;
	<span class="reserved">if</span> (cd.navtype &lt; 0) {
		s.left = oOffset.left + <span class="literal">"px"</span>;
	} <span class="reserved">else</span> {
		var mcw = mc.offsetWidth;
		<span class="reserved">if</span> (typeof mcw == <span class="literal">"undefined"</span>) {
			mcw = 50;
		}
		s.left = oOffset.left + oOffset.width - mcw + <span class="literal">"px"</span>;
	}
	s.top = oOffset.top + oOffset.height + <span class="literal">"px"</span>;
	cal.updateWCH(mc);
};

<span class="comment">/**
 * Same as the above, this function displays the history combo box for the
 * active calendar.
 */</span>
Zapatec.Calendar.showHistoryCombo = <span class="reserved">function</span>() {
	var cal = Zapatec.Calendar.activeCalendar;
	var a, h, i, cd, hc, s, tmp, div;
	<span class="reserved">if</span> (!cal)
		<span class="reserved">return</span> false;
	hc = cal.histCombo;
	<span class="reserved">while</span> (hc.firstChild)
		hc.removeChild(hc.lastChild);

	<span class="reserved">if</span> (cal.config.prefs.history) {
		a = cal.config.prefs.history.split(/,/);
		i = 0;
		<span class="reserved">while</span> (tmp = a[i++]) {
			tmp = tmp.split(/\<span class="comment">//);</span>
			h = Zapatec.Utils.createElement(<span class="literal">"div"</span>);
			h.className = Zapatec.is_ie ? <span class="literal">"label-IEfix"</span> : <span class="literal">"label"</span>;
			h.id = <span class="literal">"zpCal"</span> + cal.id + <span class="literal">"HistoryDropdownItem"</span> + (i - 1);
			h.histDate = new Date(parseInt(tmp[0], 10), parseInt(tmp[1], 10) - 1, parseInt(tmp[2], 10),
				tmp[3] ? parseInt(tmp[3], 10) : 0,
				tmp[4] ? parseInt(tmp[4], 10) : 0);
			h.appendChild(window.document.createTextNode(zapatecDate.print.call(cal, h.histDate, cal.historyDateFormat)));
			hc.appendChild(h);
			<span class="reserved">if</span> (Zapatec.Date.dateEqualsTo(h.histDate, cal.config.date))
				Zapatec.Utils.addClass(h, <span class="literal">"active"</span>);
		}
	}
	cd = cal.activeDiv;
	var oOffset = zapatecUtils.getElementOffsetRelative(cd);
	s = hc.style;
	s.display = <span class="literal">"block"</span>;
	s.left = Math.floor(oOffset.left + (oOffset.width - hc.offsetWidth) / 2) + <span class="literal">"px"</span>;
	s.top = oOffset.top + oOffset.height + <span class="literal">"px"</span>;
	cal.updateWCH(hc);
	cal.bEventShowHistory = true; <span class="comment">// Set state the we DID enter History event</span>
};

<span class="comment">/**
 * Displays the years combo box for the active calendar.  The "fwd" parameter
 * tells it if it should display future (right) or past (left) years.
 *
 * <span class="attrib">@param</span> fwd [boolean] true if it's for the right combo (future), false
 * otherwise.
 */</span>
Zapatec.Calendar.showYearsCombo = <span class="reserved">function</span> (fwd) {
	var cal = Zapatec.Calendar.activeCalendar;
	<span class="reserved">if</span> (!cal) {
		<span class="reserved">return</span> false;
	}
	var cd = cal.activeDiv;
	var yc = cal.yearsCombo;

	<span class="reserved">if</span> (cal.hilitedYear) {
		Zapatec.Utils.removeClass(cal.hilitedYear, <span class="literal">"hilite"</span>);
	}
	<span class="reserved">if</span> (cal.activeYear) {
		Zapatec.Utils.removeClass(cal.activeYear, <span class="literal">"active"</span>);
	}
	cal.activeYear = null;
	var Y = cal.config.date.getFullYear() + (fwd ? 1 : -1);
	var yr = yc.firstChild;
	var show = false;
	<span class="reserved">for</span> (var i = 12; i &gt; 0; --i) {
		<span class="reserved">if</span> (Y &gt;= cal.minYear &amp;&amp; Y &lt;= cal.maxYear) {
			yr.firstChild.data = Y;
			yr.year = Y;
			yr.style.display = <span class="literal">"block"</span>;
			show = true;
		} <span class="reserved">else</span> {
			yr.style.display = <span class="literal">"none"</span>;
		}
		yr = yr.nextSibling;
		Y += fwd ? cal.config.step : -cal.config.step;
	}
	<span class="reserved">if</span> (show) {
		var oOffset = zapatecUtils.getElementOffsetRelative(cd);
		var s = yc.style;
		s.display = <span class="literal">"block"</span>;
		<span class="reserved">if</span> (cd.navtype &lt; 0) {
			s.left = oOffset.left + <span class="literal">"px"</span>;
		} <span class="reserved">else</span> {
			var ycw = yc.offsetWidth;
			<span class="reserved">if</span> (typeof ycw == <span class="literal">"undefined"</span>) {
				ycw = 50;
			}
			s.left = oOffset.left + oOffset.width - ycw + <span class="literal">"px"</span>;
		}
		s.top = oOffset.top + oOffset.height + <span class="literal">"px"</span>;
	}
	cal.updateWCH(yc);
};

<span class="comment">/**
 * This is a simple function that stops a "mousedown" related to the calendar's
 * table element.  This helps avoiding text selection in certain browsers (most
 * notably, Safari, since Mozilla already has a better way).
 *
 * <span class="attrib">@param</span> ev [Event] the Event object
 * <span class="attrib">@return</span> false
 */</span>
Zapatec.Calendar.tableMouseDown = <span class="reserved">function</span> (ev) {
	<span class="reserved">if</span> (Zapatec.Utils.getTargetElement(ev) == Zapatec.Utils.getElement(ev)) {
		<span class="reserved">return</span> Zapatec.Utils.stopEvent(ev);
	}
};

<span class="comment">/**
 * Called when the mouse button is pressed upon a button.  The name of this
 * function is so for historical reasons; currently, this function is used for
 * \em any type of buttons used in the calendar, not only "days".
 *
 * This function does quite some things.  It checks if the clicked cell is the
 * title bar or the status bar, in which case it starts the calendar dragging
 * mechanism (cal._dragStart()).  If the cell is a time part, then it registers
 * Zapatec.Calendar.tableMouseOver() event handler on the document.  If the
 * cell is a "navigation" button (next/prev year or month, or today) then a
 * timeout is created that will show the appropriate combo box if the button is
 * not quickly depressed.
 *
 * <span class="attrib">@param</span> ev [Event] the event object
 * <span class="attrib">@return</span> false
 */</span>
Zapatec.Calendar.dayMouseDown = <span class="reserved">function</span>(ev) {
	var canDrag = true;
	var el = Zapatec.Utils.getElement(ev);
	<span class="reserved">if</span> (el.className.indexOf(<span class="literal">"disabled"</span>) != -1 || el.className.indexOf(<span class="literal">"true"</span>) != -1) {
		<span class="reserved">return</span> false;
	}
	var cal = el.calendar;
	<span class="comment">//BEGIN: fix for the extra information bug in IE</span>
	var parent = el.parentNode;
	<span class="reserved">if</span> (parent.className.indexOf(<span class="literal">"disabled"</span>) != -1 || parent.className.indexOf(<span class="literal">"true"</span>) != -1) {
		<span class="reserved">return</span> false;
	}
	<span class="reserved">while</span> (!cal) {
		el = el.parentNode;
		cal = el.calendar;
	}
	<span class="comment">//END</span>
	cal.bEventShowHistory = false;  <span class="comment">// Set state the we DID NOT enter History event</span>
	cal.activeDiv = el;
	Zapatec.Calendar.activeCalendar = cal;
	<span class="reserved">if</span> (el.navtype != 300) {
		<span class="reserved">if</span> (el.navtype == 50 || el.navtype == 51) {
			<span class="comment">//turns off changing the time by dragging if timeInterval is set</span>
			<span class="reserved">if</span> (!((cal.config.timeInterval == null) || ((cal.config.timeInterval &lt; 60) &amp;&amp; (el.className.indexOf(<span class="literal">"hour"</span>, 0) != -1)))) {
				canDrag = false;
			}
			el._current = el.firstChild.data;
			<span class="reserved">if</span> (canDrag) {
				Zapatec.Utils.addEvent(window.document, <span class="literal">"mousemove"</span>, Zapatec.Calendar.tableMouseOver);
			}
		} <span class="reserved">else</span> {
			<span class="reserved">if</span> (((el.navtype == 201) || (el.navtype == 202) || (el.navtype == 211) || (el.navtype == 212)) &amp;&amp; (cal.config.timeInterval &gt; 30) &amp;&amp; (el.timePart.className.indexOf(<span class="literal">"minute"</span>, 0) != -1)) {
				canDrag = false;
			}
			<span class="reserved">if</span> (canDrag) {
				Zapatec.Utils.addEvent(window.document, Zapatec.is_ie5 ? <span class="literal">"mousemove"</span> : <span class="literal">"mouseover"</span>, Zapatec.Calendar.tableMouseOver);
			}
		}
		<span class="reserved">if</span> (canDrag &amp;&amp; !(el.navtype == 200 &amp;&amp; cal.closeButton) &amp;&amp; !(el.navtype == 400 &amp;&amp; cal.helpButton)) {
			Zapatec.Utils.addClass(el, <span class="literal">"hilite"</span>);
			Zapatec.Utils.addClass(el, <span class="literal">"active"</span>);
		}
		Zapatec.Utils.addEvent(window.document, <span class="literal">"mouseup"</span>, Zapatec.Calendar.tableMouseUp);
	} <span class="reserved">else</span> <span class="reserved">if</span> (cal.isPopup) {
		cal._dragStart(ev);
	} <span class="reserved">else</span> {
		Zapatec.Calendar.activeCalendar = null;
	}
	<span class="reserved">if</span> (el.navtype == -1 || el.navtype == 1) {
		<span class="reserved">if</span> (cal.timeout) clearTimeout(cal.timeout);
		cal.timeout = setTimeout(<span class="literal">"Zapatec.Calendar.showMonthsCombo()"</span>, 250);
	} <span class="reserved">else</span> <span class="reserved">if</span> (el.navtype == -2 || el.navtype == 2) {
		<span class="reserved">if</span> (cal.timeout) clearTimeout(cal.timeout);
		cal.timeout = setTimeout((el.navtype &gt; 0) ? <span class="literal">"Zapatec.Calendar.showYearsCombo(true)"</span> : <span class="literal">"Zapatec.Calendar.showYearsCombo(false)"</span>, 250);
	} <span class="reserved">else</span> <span class="reserved">if</span> (el.navtype == 0 &amp;&amp; cal.config.prefs.history) {
		<span class="reserved">if</span> (cal.timeout) clearTimeout(cal.timeout);
		cal.timeout = setTimeout(<span class="literal">"Zapatec.Calendar.showHistoryCombo()"</span>, 250);
	} <span class="reserved">else</span> {
		cal.timeout = null;
	}

	<span class="reserved">return</span> Zapatec.Utils.stopEvent(ev);
};

<span class="comment">/**
 * Dblclick event handler. Fires calDateDblclicked event if a date is double
 * clicked. In IE voids the selection.
 * <span class="attrib">@private</span>
 */</span>
Zapatec.Calendar.dayMouseDblClick = <span class="reserved">function</span>() {
	var oEv = window.event;
	var oEl = oEv.currentTarget || oEv.srcElement;
	var oCal = oEl.calendar;
	<span class="reserved">while</span> (!oCal) {
		oEl = oEl.parentNode;
		oCal = oEl.calendar;
	}
	<span class="reserved">if</span> (typeof oEl.navtype == <span class="literal">'undefined'</span>) {
		oCal.fireEvent(<span class="literal">'calDateDblclicked'</span>, oCal.currentDate);
	}
	<span class="reserved">if</span> (Zapatec.is_ie) {
		window.document.selection.empty();
	}
};

<span class="comment">/**
 * This function gets called at "onmouseover" events that trigger on any kind
 * of button, like dates, navigation buttons, etc.  Basically, the function
 * computes and caches the tooltip (if it's a date cell for instance) and
 * displays it in the status bar.  If the cell is not a navigation button, it
 * will also add "rowhilite" class to the containing TR element.
 *
 * <span class="attrib">@param</span> ev [Event] the event object.
 * <span class="attrib">@return</span> false
 */</span>
Zapatec.Calendar.dayMouseOver = <span class="reserved">function</span>(ev) {
	var el = Zapatec.Utils.getElement(ev);
	<span class="comment">//BEGIN: fix for the extra information bug in IE</span>
	<span class="reserved">while</span> (!el.calendar) {
		el = el.parentNode;
		caldate = el.caldate;
	}
	<span class="comment">//END</span>
	var cal = el.calendar;
	caldate = el.caldate;
	var cel = el.timePart;
	<span class="reserved">if</span> (caldate) {
		caldate = new Date(caldate[0], caldate[1], caldate[2]);
		<span class="reserved">if</span> (caldate.getDate() != el.caldate[2]) caldate.setDate(el.caldate[2]);
	}
	<span class="reserved">if</span> (Zapatec.Utils.isRelated(el, ev) || el.className.indexOf(<span class="literal">"disabled"</span>) != -1 || el.className.indexOf(<span class="literal">"true"</span>) != -1) {
		<span class="reserved">return</span> false;
	}
	<span class="reserved">if</span> (el.ttip) {
		<span class="reserved">if</span> (el.ttip.substr(0, 1) == <span class="literal">"_"</span>) {
			el.ttip = zapatecDate.print.call(cal, caldate, el.calendar.ttDateFormat) + el.ttip.substr(1);
		}
		cal.showHint(el.ttip);
	}
	<span class="reserved">if</span> (el.navtype != 300) {
		<span class="comment">//turns off highliting of the time part which can not be changed by dragging</span>
		<span class="reserved">if</span> (!((cal.config.timeInterval == null) || (el.className.indexOf(<span class="literal">"ampm"</span>, 0) != -1) || ((cal.config.timeInterval &lt; 60) &amp;&amp; (el.className.indexOf(<span class="literal">"hour"</span>, 0) != -1))) &amp;&amp; (el.navtype == 50)) {
			<span class="reserved">return</span> Zapatec.Utils.stopEvent(ev);
		}
		<span class="reserved">if</span> (((el.navtype == 201) || (el.navtype == 202)) &amp;&amp; (cal.config.timeInterval &gt; 30) &amp;&amp; (cel.className.indexOf(<span class="literal">"minute"</span>, 0) != -1)) {
			<span class="reserved">return</span> Zapatec.Utils.stopEvent(ev);
		}
		<span class="reserved">if</span> (!(el.navtype == 200 &amp;&amp; cal.closeButton) &amp;&amp; !(el.navtype == 400 &amp;&amp; cal.helpButton))
			Zapatec.Utils.addClass(el, <span class="literal">"hilite"</span>);
		<span class="reserved">if</span> (caldate &amp;&amp; el.className.indexOf(<span class="literal">"disabled"</span>) == -1 &amp;&amp; el.className.indexOf(<span class="literal">"true"</span>) == -1) {
			<span class="reserved">if</span> (cal.lastRowHilite) {
				Zapatec.Utils.removeClass(cal.lastRowHilite, <span class="literal">"rowhilite"</span>);
				cal.lastRowHilite = null;
			}
			Zapatec.Utils.addClass(el.parentNode, <span class="literal">"rowhilite"</span>);
		}
	}

	<span class="reserved">return</span> Zapatec.Utils.stopEvent(ev);
};

<span class="comment">/**
 * Gets called when the mouse leaves a button.  This function "undoes" what
 * dayMouseOver did, that is, it removes the "rowhilite" class from the
 * containing TR and restores the status bar display to read "Select date".
 *
 * <span class="attrib">@param</span> ev [Event] the event object.
 * <span class="attrib">@return</span> false
 */</span>
Zapatec.Calendar.dayMouseOut = <span class="reserved">function</span>(ev) {
	var el = Zapatec.Utils.getElement(ev);
	<span class="comment">//BEGIN: fix for the extra information bug in IE</span>
	<span class="reserved">while</span> (!el.calendar) {
		el = el.parentNode;
		caldate = el.caldate;
	}
	<span class="comment">//END</span>
	var cal = el.calendar;
	caldate = el.caldate;
	<span class="reserved">if</span> (Zapatec.Utils.isRelated(el, ev) || el.className.indexOf(<span class="literal">"disabled"</span>) != -1 || el.className.indexOf(<span class="literal">"true"</span>) != -1)
		<span class="reserved">return</span> false;
	Zapatec.Utils.removeClass(el, <span class="literal">"hilite"</span>);
	<span class="reserved">if</span> (caldate)
		Zapatec.Utils.removeClass(el.parentNode, <span class="literal">"rowhilite"</span>);
	<span class="reserved">if</span> (cal)
		cal.showHint(Zapatec.Calendar.i18n(<span class="literal">"SEL_DATE"</span>, null, cal));
	<span class="reserved">return</span> Zapatec.Utils.stopEvent(ev);
};

<span class="comment">/**
 * The generic "click" handler.  This function handles actions on any kind of
 * buttons that appear inside our calendar.  It determines the button type by
 * querying \em el.navtype.  The following types of objects are supported:
 *
 * - Date cells (navtype is undefined).  The function will select that date,
 *	add appropriate class names and remove them from the previously selected
 *	date.  If the date in the calendar \em has \em changed, it calls the
 *	calendar's onSelect handler (see the constructor).  If multiple dates is
 *	enabled, it will not unselect previously selected date but rather maintain
 *	an array of dates which will be avaliable to the onSelect or onClose
 *	handler.
 * - The Close button (navtype == 200).  If this is clicked, then the
 *	calendar's onClose handler is called immediately.
 * - The Today button (navtype == 0).  The calendar will jump to the "today"
 *	date and time, unless it's already there.
 * - The About button (navtype == 400).  It will display an alert with the
 *	"about message", as defined in the translation file.
 * - Previous year (navtype == -2)
 * - Previous month (navtype == -1)
 * - Next month (navtype == 1)
 * - Next year (navtype == 2)
 * - Day names (navtype == 100).  If any of them is clicked, the calendar will
 *	display that day as the first day of week.  It calls the "onFDOW" event
 *	handler if defined.
 * - Time parts (navtype == 50).  If any of them is clicked, this function will
 *	determine if it's a click or shift-click, and will take the appropriate
 *	action (simple click means add 1, shift-click means substract 1 from that
 *	time part).  Then it calls onUpdateTime() to refresh the display.
 * - Week number clicked (navtype == 150)
 *
 * - Time scroll buttons (navtype == 201 or navtype == 202).  If such buttons
 *	are clicked, the time part involved is determined and it is incremented or
 *	decremented with the current step (default: 5).  201 is for "add", 202 for
 *	"substract".
 *
 * <span class="attrib">@param</span> el [HTMLElement] the object being clicked on
 */</span>
Zapatec.Calendar.cellClick = <span class="reserved">function</span>(el, ev) {
	var cal = el.calendar;
	var closing = false;
	var newdate = false;
	var date = null;
	<span class="comment">//BEGIN: fix for the extra information bug in IE</span>
	<span class="reserved">while</span> (!cal) {
		el = el.parentNode;
		cal = el.calendar;
	}
	<span class="comment">//END fix</span>
	<span class="reserved">if</span> (el.className.indexOf(<span class="literal">"disabled"</span>) != -1 || el.className.indexOf(<span class="literal">"true"</span>) != -1) {
		Zapatec.Utils.removeClass(el, <span class="literal">"hilite"</span>);
		<span class="reserved">return</span> false;
	}

	<span class="comment">// if sel can not choosing</span>
	<span class="reserved">if</span> (cal.config.multiple &amp;&amp; cal.config.maxSelection &gt; 0 &amp;&amp; (cal._getMultipleLength() + 1) &gt; cal.config.maxSelection) {
		<span class="reserved">return</span>;
	}

	<span class="reserved">if</span> (typeof el.navtype == <span class="literal">"undefined"</span>) {
		<span class="reserved">if</span> (cal.currentDateEl) {
			Zapatec.Utils.removeClass(cal.currentDateEl, <span class="literal">"selected"</span>);
			Zapatec.Utils.addClass(el, <span class="literal">"selected"</span>);
			closing = (cal.currentDateEl == el);
			<span class="reserved">if</span> (!closing) {
				cal.currentDateEl = el;
			}
		}
		var tmpDate = new Date(el.caldate[0], el.caldate[1], el.caldate[2]);
		<span class="reserved">if</span> (tmpDate.getDate() != el.caldate[2]) {
			tmpDate.setDate(el.caldate[2]);
		}
		Zapatec.Date.setDateOnly(cal.config.date, tmpDate);
		Zapatec.Date.setDateOnly(cal.currentDate, tmpDate);
		<span class="reserved">if</span> (cal.currentDateEnd) {
			Zapatec.Date.setDateOnly(cal.currentDateEnd, tmpDate);
		}
		date = cal.config.date;
		cal.dateClicked = true;
		<span class="reserved">if</span> (cal.config.multiple) {
			cal.toggleMultipleDate(new Date(cal.currentDate), new Date(cal.currentDateEnd));
		}
		<span class="comment">// Update history only if date selected</span>
		<span class="reserved">if</span> (!cal.config.noHistory) {
			cal.updateHistory();
		}
		newdate = true;
		cal.onSetTime();
		<span class="comment">// Fire event</span>
		<span class="reserved">if</span> (ev) {
			<span class="comment">// On dblclick fire event only once</span>
			var iNow = Date.parse(new Date());
			<span class="reserved">if</span> (!cal.calDateClicked || iNow - cal.calDateClicked &gt; 500) {
				cal.fireEvent(<span class="literal">'calDateClicked'</span>, tmpDate);
				cal.calDateClicked = iNow;
			}
		} <span class="reserved">else</span> {
			cal.fireEvent(<span class="literal">'calDateSwitched'</span>, tmpDate);
		}
	} <span class="reserved">else</span> {
		<span class="reserved">if</span> (el.navtype == 200) {
			<span class="reserved">if</span> (!cal.closeButton) {
				Zapatec.Utils.removeClass(el, <span class="literal">"hilite"</span>);
				cal.callCloseHandler();
			}
			<span class="reserved">return</span>;
		}
		date = new Date(cal.config.date);
		<span class="comment">// Set date to Today if Today clicked AND History NOT shown</span>
		<span class="reserved">if</span> (el.navtype == 0 &amp;&amp; !cal.bEventShowHistory) {
			<span class="comment">// TODAY</span>
			Zapatec.Date.setDateOnly(date, new Date());
		}
		<span class="comment">// unless "today" was clicked, we assume no date was clicked so</span>
		<span class="comment">// the selected handler will know not to close the calenar when</span>
		<span class="comment">// in single-click mode.</span>
		<span class="comment">// cal.dateClicked = (el.navtype == 0);</span>
		cal.dateClicked = false;
		var year = date.getFullYear();
		var mon = date.getMonth();
		<span class="reserved">function</span> setMonth(m) {
			var day = date.getDate();
			var max = Zapatec.Date.getMonthDays(date, m);
			<span class="reserved">if</span> (day &gt; max) {
				date.setDate(max);
			}
			date.setMonth(m);
		}
		;

		var dateStart = null;
		switch (el.navtype) {

			case 400:
				<span class="reserved">if</span> (!cal.helpButton) {
					Zapatec.Utils.removeClass(el, <span class="literal">"hilite"</span>);
					cal.callHelpHandler();
				}
				<span class="reserved">return</span>;

			case -2:
				<span class="reserved">if</span> (year &gt; cal.minYear) {
					Zapatec.Date.setFullYear(date, year - 1);
					<span class="comment">// Call user function after year selected</span>
					<span class="reserved">if</span> (typeof cal.config.onYearSelect == <span class="literal">"function"</span>)
						cal.config.onYearSelect(year - 1);
				}
				break;

			case -1:
				<span class="reserved">if</span> (mon &gt; 0) {
					setMonth(mon - cal.config.stepMonths);
				} <span class="reserved">else</span> <span class="reserved">if</span> (year-- &gt; cal.minYear) {
					Zapatec.Date.setFullYear(date, year);
					setMonth(11);
				}
			<span class="comment">// Call user function after month selected</span>
				<span class="reserved">if</span> (typeof cal.config.onMonthSelect == <span class="literal">"function"</span>) {
					cal.config.onMonthSelect(mon &gt; 0 ? mon - 1 : 11);
				}
				break;

			case 1:
				<span class="reserved">if</span> (mon &lt; 11) {
					setMonth(mon + cal.config.stepMonths);
				} <span class="reserved">else</span> <span class="reserved">if</span> (year &lt; cal.maxYear) {
					Zapatec.Date.setFullYear(date, year + 1);
					setMonth(0);
				}
			<span class="comment">// Call user function after month selected</span>
				<span class="reserved">if</span> (typeof cal.config.onMonthSelect == <span class="literal">"function"</span>) {
					cal.config.onMonthSelect(mon &lt; 11 ? mon + 1 : 0);
				}
				break;

			case 2:
				<span class="reserved">if</span> (year &lt; cal.maxYear) {
					Zapatec.Date.setFullYear(date, year + 1);
					<span class="comment">// Call user function after year selected</span>
					<span class="reserved">if</span> (typeof cal.config.onYearSelect == <span class="literal">"function"</span>) {
						cal.config.onYearSelect(year + 1);
					}
				}
				break;

			case 100:
				cal.setFirstDayOfWeek(el.fdow);
				cal.config.prefs.fdow = cal.config.firstDay;
				Zapatec.Calendar.savePrefs(cal.id);
				<span class="reserved">if</span> (cal.config.onFDOW) {
					cal.config.onFDOW(cal.config.firstDay);
				}
				<span class="reserved">return</span>;

			case 150:
				<span class="reserved">if</span> (cal.config.onWeekClick) {
					cal.config.onWeekClick(el.innerHTML);
				}
				<span class="reserved">return</span>;

			case 50:
			case 51:
			<span class="comment">//turns off time changing if timeInterval is set with special value</span>
				var date = cal.currentDate;
				<span class="reserved">if</span> (el.navtype == 51) {
					date = cal.currentDateEnd;
					dateStart = cal.currentDate;
				}
			<span class="comment">// always check ampm changes</span>
				<span class="reserved">if</span> (el.className.indexOf(<span class="literal">"ampm"</span>, 0) &lt; 0 &amp;&amp;
					 !((cal.config.timeInterval == null) || ((cal.config.timeInterval &lt; 60) &amp;&amp; (el.className.indexOf(<span class="literal">"hour"</span>, 0) != -1)))) {
					break;
				}
				var range = el._range;
				var current = el.firstChild.data;
				var pm = (date.getHours() &gt;= 12);
				<span class="reserved">for</span> (var i = range.length; --i &gt;= 0;) {
					<span class="reserved">if</span> (range[i] == current) {
						break;
					}
				}
				<span class="reserved">if</span> (ev &amp;&amp; ev.shiftKey) {
					<span class="reserved">if</span> (--i &lt; 0) {
						i = range.length - 1;
					}
				} <span class="reserved">else</span> <span class="reserved">if</span> (++i &gt;= range.length) {
					i = 0;
				}
			<span class="comment">//ALLOWED TIME CHECK</span>
			<span class="comment">// Fills "minute" and "hour" variables with the time that user wants to set, to pass them to the dateStatusHandler.</span>
			<span class="comment">// As the script passes hours in 24 format, we need to convert inputed values if they are not in the needed format</span>
				var minute = null; <span class="comment">// minutes to be passed</span>
				var hour = null; <span class="comment">// hours to be passed</span>
			<span class="comment">// as we pass date element to the handler, we need to create new one and fill it with new minutes or hours (depending on what had changed)</span>
				var new_date = new Date(date);
			<span class="comment">// if "ampm" was clicked</span>
				<span class="reserved">if</span> (el.className.indexOf(<span class="literal">"ampm"</span>, 0) != -1) {
					minute = date.getMinutes(); <span class="comment">// minutes didn't change</span>
					<span class="comment">// if the "ampm" value has changed we need to correct hours (add 12 or exclude 12 or set it to zero)</span>
					hour = (range[i] == Zapatec.Calendar.i18n(<span class="literal">"pm"</span>, <span class="literal">"ampm"</span>, cal)) ? ((date.getHours() == 12) ? (date.getHours()) : (date.getHours() + 12)) : (date.getHours() - 12);
					<span class="comment">// if the time is disabled we seek the first one disabled.</span>
					<span class="comment">// It fixes the bug when you can not change from 'am' to 'pm' or vice versa for the dates that have restrictions for time.</span>
					<span class="comment">// This part of code is very easy to understand, so it don't need much comments</span>
					<span class="reserved">if</span> (cal.getDateStatus &amp;&amp; cal.getDateStatus(new_date, date.getFullYear(), date.getMonth(), date.getDate(), parseInt(hour, 10), parseInt(minute, 10))) {
						var dirrect;
						<span class="reserved">if</span> (range[i] == Zapatec.Calendar.i18n(<span class="literal">"pm"</span>, <span class="literal">"ampm"</span>, cal)) {
							dirrect = -5;
						} <span class="reserved">else</span> {
							dirrect = 5;
						}
						hours = hour;
						minutes = minute;
						do {
							minutes += dirrect;
							<span class="reserved">if</span> (minutes &gt;= 60) {
								minutes -= 60;
								++hours;
								<span class="reserved">if</span> (hours &gt;= 24) {
									hours -= 24;
								}
								new_date.setHours(hours);
							}
							<span class="reserved">if</span> (minutes &lt; 0) {
								minutes += 60;
								--hours;
								<span class="reserved">if</span> (hours &lt; 0) {
									hours += 24;
								}
								new_date.setHours(hours);
							}
							new_date.setMinutes(minutes);
							<span class="reserved">if</span> (dateStart) {
								<span class="reserved">if</span> (new_date.getHours() &gt; dateStart.getHourse()) {
									new_date.setHours(dateStart.getHourse());
								}
								<span class="reserved">if</span> (new_date.Minutes() &gt; dateStart.Minutes()) {
									new_date.setMinutes(dateStart.getMinutes() + 1);
								}
							}
							<span class="reserved">if</span> (!cal.getDateStatus(new_date, date.getFullYear(), date.getMonth(), date.getDate(), parseInt(hours, 10), parseInt(minutes, 10))) {
								hour = hours;
								minute = minutes;
								<span class="reserved">if</span> (hour &gt; 12) {
									i = 1;
								} <span class="reserved">else</span> {
									i = 0;
								}
								<span class="reserved">if</span> (dateStart) {
									var tmpDate = new Date(cal.config.dateEnd);
									tmpDate.setHours(hour);
									tmpDate.setMinutes(minute);
									<span class="reserved">if</span> (hour &gt; dateStart.getHours()) {
										hour = dateStart.getHours();
									}
									<span class="reserved">if</span> (minute &gt; dateStart.getMinutes() &gt; dateStart.getMinutes() &amp;&amp; cal.config.dateEnd &lt; dateStart) {
										minute = dateStart.getMinutes();
									}
									cal.config.dateEnd.setHours(hour);
									cal.config.dateEnd.setMinutes(minute);
									cal.onSetTime(cal.currentDateEnd);
								} <span class="reserved">else</span> {
									cal.config.date.setHours(hour);
									cal.config.date.setMinutes(minute);
									cal.onSetTime();
								}
							}
						} <span class="reserved">while</span> ((hour != hours) || (minute != minutes));
					}
					<span class="comment">// updates our new Date object that will be passed to the handler</span>
					new_date.setHours(hour);
				}
			<span class="comment">// if hours were clicked</span>
				<span class="reserved">if</span> (el.className.indexOf(<span class="literal">"hour"</span>, 0) != -1) {
					minute = date.getMinutes(); <span class="comment">// minutes didn't change</span>
					hour = (!cal.time24) ? ((pm) ? ((range[i] != 12) ? (parseInt(range[i], 10) + 12) : (12)) : ((range[i] != 12) ? (range[i]) : (0))) : (range[i]);  <span class="comment">// new value of hours</span>
					new_date.setHours(hour);
				}
			<span class="comment">// if minutes were clicked</span>
				<span class="reserved">if</span> (el.className.indexOf(<span class="literal">"minute"</span>, 0) != -1) {
					hour = date.getHours(); <span class="comment">// hours didn't change</span>
					minute = range[i]; <span class="comment">// new value of minutes</span>
					new_date.setMinutes(minute);
				}
				var status = false;
			<span class="comment">// if the handler is set, we pass new values and retreive result in "status" variable</span>
				<span class="reserved">if</span> (cal.getDateStatus) {
					status = cal.getDateStatus(new_date, date.getFullYear(), date.getMonth(), date.getDate(), parseInt(hour, 10), parseInt(minute, 10));
					<span class="reserved">if</span> (dateStart &amp;&amp; (hour &lt; dateStart.getHours() || minute &lt; dateStart.getMinutes())) {
						status = true;
					}
				}
				<span class="reserved">if</span> (dateStart) {
					var testDate = new Date(new_date);
					testDate.setHours = parseInt(hour, 10);
					testDate.setMinutes = parseInt(minute, 10);
					<span class="reserved">if</span> (testDate &lt; cal.currentDate) {
						status = true;
					}
				}
				<span class="reserved">if</span> (!status) {
					el.firstChild.data = range[i];
				}
			<span class="comment">//END OF ALLOWED TIME CHECK</span>
				<span class="reserved">if</span> (dateStart) {
					cal.onUpdateTime(cal.currentDateEnd);
				} <span class="reserved">else</span> {
					cal.onUpdateTime();
				}
				<span class="reserved">return</span>;

			case 211:
			case 212:
				dateStart = cal.currentDate;

			case 201: <span class="comment">// timepart, UP</span>
			case 202: <span class="comment">// timepart, DOWN</span>
				var cel = el.timePart;
			<span class="comment">//turns off time changing if timeInterval is set with special value</span>
				var date = null;
				<span class="reserved">if</span> (dateStart) {
					date = cal.currentDateEnd;
				} <span class="reserved">else</span> {
					date = cal.currentDate;
				}
				<span class="reserved">if</span> ((cel.className.indexOf(<span class="literal">"minute"</span>, 0) != -1) &amp;&amp; (cal.config.timeInterval &gt; 30)) {
					break;
				}
				var val = parseInt(cel.firstChild.data, 10);
				var pm = (date.getHours() &gt;= 12);
				var range = cel._range;
				<span class="reserved">for</span> (var i = range.length; --i &gt;= 0;) {
					<span class="reserved">if</span> (val == range[i]) {
						val = i;
						break;
					}
				}
				var step = cel._step;
				<span class="reserved">if</span> (el.navtype == 201 || el.navtype == 211) {
					val = step * Math.floor(val / step);
					val += step;
					<span class="reserved">if</span> (val &gt;= range.length) {
						val = 0;
					}
				} <span class="reserved">else</span> {
					val = step * Math.ceil(val / step);
					val -= step;
					<span class="reserved">if</span> (val &lt; 0) {
						val = range.length - step;
					}
				}
			<span class="comment">//ALLOWED TIME CHECK</span>
			<span class="comment">//if (cal.getDateStatus) { //Current time is changing, check with the callback to see if it's in range of allowed times</span>
			<span class="comment">// Fills "minute" and "hour" variables with the time that user wants to set, to pass them to the dateStatusHandler.</span>
			<span class="comment">// As the script passes hours in 24 format, we need to convert inputed values if they are not in the needed format</span>
				var minute = null; <span class="comment">// minutes to be passed</span>
				var hour = null; <span class="comment">// hours to be passed</span>
			<span class="comment">// as we pass date element to the handler, we need to create new one and fill it with new minutes or hours (depending on what had changed)</span>
				var new_date = new Date(date);
			<span class="comment">// if hours were changed</span>
				<span class="reserved">if</span> (cel.className == <span class="literal">"hour"</span>) {
					minute = date.getMinutes();
					hour = (!cal.time24) ? ((pm) ? ((range[val] != 12) ? (parseInt(range[val], 10) + 12) : (12)) : ((range[val] != 12) ? (range[val]) : (0))) : (range[val]);
					new_date.setHours(hour);
				}
			<span class="comment">// if minutes were changed</span>
				<span class="reserved">if</span> (cel.className == <span class="literal">"minute"</span>) {
					hour = date.getHours();
					minute = val;
					new_date.setMinutes(range[val]);
				}
				var status = false;
			<span class="comment">// if the handler is set, we pass new values and retreive result in "status" variable</span>
				<span class="reserved">if</span> (cal.getDateStatus) {
					status = cal.getDateStatus(new_date, date.getFullYear(), date.getMonth(), date.getDate(), parseInt(hour, 10), parseInt(minute, 10));
					<span class="reserved">if</span> (dateStart &amp;&amp; (hour &lt; dateStart.getHours() || minute &lt; dateStart.getMinutes())) {
						status = true;
					}
				}
				<span class="reserved">if</span> (dateStart) {
					var testDate = new Date(new_date);
					testDate.setHours = parseInt(hour, 10);
					testDate.setMinutes = parseInt(minute, 10);
					<span class="reserved">if</span> (testDate &lt; cal.currentDate) {
						status = true;
					}
				}
				<span class="reserved">if</span> (!status) {
					cel.firstChild.data = range[val];
				}
				<span class="reserved">if</span> (dateStart) {
					cal.onUpdateTime(cal.currentDateEnd);
				} <span class="reserved">else</span> {
					cal.onUpdateTime();
				}
			<span class="comment">//END OF ALLOWED TIME CHECK</span>
				<span class="reserved">return</span>;

			case 0:
			<span class="comment">// TODAY will bring us here</span>
				<span class="reserved">if</span> (cal.config.onTodayClick) {
					cal.config.onTodayClick(el.innerHTML);
				}
			<span class="comment">//fix for the today bug for the special dates</span>
				<span class="reserved">if</span> (cal.getDateStatus &amp;&amp; ((cal.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate()) == true) || (cal.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate()) == <span class="literal">"disabled"</span>))) {
					<span class="comment">// remember, "date" was previously set to new Date() if TODAY was clicked; thus, it  contains today date.</span>
					<span class="reserved">return</span> false;
				}
				break;
		}

		<span class="reserved">if</span> (!Zapatec.Date.equalsTo(date, cal.config.date) <span class="comment">/*|| cal.config.numberMonths*/</span>) {
			<span class="reserved">if</span> (el.navtype &amp;&amp; el.navtype &gt;= -2 &amp;&amp; el.navtype &lt;= 2) {
				cal._init(cal.config.firstDay, date, true);
				<span class="reserved">return</span>;
			}
			cal.setDate(date);
			newdate = true;
			<span class="comment">// Fire event</span>
			<span class="reserved">if</span> (ev) {
				<span class="comment">// On dblclick fire event only once</span>
				var iNow = Date.parse(new Date());
				<span class="reserved">if</span> (!cal.calDateClicked || iNow - cal.calDateClicked &gt; 500) {
					cal.fireEvent(<span class="literal">'calDateClicked'</span>, date);
					cal.calDateClicked = iNow;
				}
			} <span class="reserved">else</span> {
				cal.fireEvent(<span class="literal">'calDateSwitched'</span>, date);
			}
		}
	}
	<span class="reserved">if</span> (newdate) {
		cal.callHandler();
	}
	<span class="reserved">if</span> (closing &amp;&amp; cal.isPopup) {
		Zapatec.Utils.removeClass(el, <span class="literal">"hilite"</span>);
		cal.callCloseHandler();
	}
};


<span class="comment">// event handlers</span>

<span class="comment">/**
 * This is an event handler that gets called when the mouse button is released
 * upon the document.  The name (tableMouseUp) is because of historic reasons
 * (in the initial calendar versions this event was triggered by the calendar
 * table, but now it's the document who does it).
 *
 * This function does a number of things.  It determines which is the element
 * that was actually clicked.  Note that the "mouseup" event usually means
 * "something was clicked"; it's "mouseup" who fires the "onclick" event, not
 * "mousedown" ;-).  So, if the clicked element is a member of one of the combo
 * boxes such as month, year or history, then the appropriate action is taken
 * (switch month, year or go to history date).
 *
 * Also, the Zapatec.Calendar.cellClick() function is called, which further
 * examines the target element and might do other things.
 *
 * Finally, this handler deregisters itself (it's automatically enabled at
 * "mousedown" on document), stops the event propagation, sets the static _C
 * variable to \em null (meaning "no calendar is currently in use").
 *
 * <span class="attrib">@param</span> ev [Event] the event object
 * <span class="attrib">@return</span> false
 */</span>
Zapatec.Calendar.tableMouseUp = <span class="reserved">function</span>(ev) {
	var cal = Zapatec.Calendar.activeCalendar;
	<span class="reserved">if</span> (!cal) {
		<span class="reserved">return</span> false;
	}
	<span class="reserved">if</span> (cal.timeout) {
		clearTimeout(cal.timeout);
	}
	var el = cal.activeDiv;
	<span class="reserved">if</span> (!el) {
		<span class="reserved">return</span> false;
	}
	var target = Zapatec.Utils.getTargetElement(ev);
	<span class="reserved">if</span> (typeof(el.navtype) == <span class="literal">"undefined"</span>) {
		<span class="reserved">while</span> (target &amp;&amp; !target.calendar) {
			target = target.parentNode;
		}
	}
	ev || (ev = window.event);
	Zapatec.Utils.removeClass(el, <span class="literal">"active"</span>);
	<span class="reserved">if</span> (target &amp;&amp; (target == el || target.parentNode == el)) {
		Zapatec.Calendar.cellClick(el, ev);
	}
	var mon = Zapatec.Calendar.findMonth(target);
	var date = null;
	<span class="reserved">if</span> (mon) {
		<span class="reserved">if</span> (!mon.disabled) {
			date = new Date(cal.config.date);
			<span class="reserved">if</span> (mon.month != date.getMonth()) {
				date.setMonth(mon.month);
				date.setMonth(mon.month);
				cal.setDate(date, true);
				cal.dateClicked = false;
				cal.callHandler();
			}
		}
		<span class="comment">// Call user function after month selected</span>
		<span class="reserved">if</span> (typeof cal.config.onMonthSelect == <span class="literal">"function"</span>)
			cal.config.onMonthSelect(mon.month);
	} <span class="reserved">else</span> {
		var year = Zapatec.Calendar.findYear(target);
		<span class="reserved">if</span> (year) {
			date = new Date(cal.config.date);
			<span class="reserved">if</span> (year.year != date.getFullYear()) {
				Zapatec.Date.setFullYear(date, year.year);
				cal.setDate(date, true);
				cal.dateClicked = false;
				cal.callHandler();
			}
			<span class="comment">// Call user function after year selected</span>
			<span class="reserved">if</span> (typeof cal.config.onYearSelect == <span class="literal">"function"</span>)
				cal.config.onYearSelect(year.year);
		} <span class="reserved">else</span> {
			var hist = Zapatec.Calendar.findHist(target);
			<span class="reserved">if</span> (hist &amp;&amp; !Zapatec.Date.dateEqualsTo(hist.histDate, cal.config.date)) {
				<span class="comment">//Zapatec.Date.setDateOnly((date = new Date(cal.config.date)), hist.histDate);</span>
				date = new Date(hist.histDate);
				cal._init(cal.config.firstDay, cal.config.date = date);
				cal.dateClicked = false;
				cal.callHandler();
				<span class="comment">// Call user function after history selected</span>
				<span class="reserved">if</span> (typeof cal.config.onHistorySelect == <span class="literal">"function"</span>)
					cal.config.onHistorySelect(hist.histDate);
			}
		}
	}

	Zapatec.Utils.removeEvent(window.document, <span class="literal">"mouseup"</span>, Zapatec.Calendar.tableMouseUp);
	Zapatec.Utils.removeEvent(window.document, <span class="literal">"mouseover"</span>, Zapatec.Calendar.tableMouseOver);
	Zapatec.Utils.removeEvent(window.document, <span class="literal">"mousemove"</span>, Zapatec.Calendar.tableMouseOver);

	cal._hideCombos();

	<span class="reserved">return</span> Zapatec.Utils.stopEvent(ev);
};

<span class="comment">/**
 * Event handler that gets called when the end-user moves the mouse over the
 * document.
 *
 * This function is pretty complicated too.  It adds hover/active state class
 * to elements that are highlighted and/or clicked.  It determines whether one
 * is trying to modify the time by "drag'n'drop" (the original interface
 * implemented by the calendar).  Finally, it determines if the
 * mouse is over combo box items, also adding/removing hover states and setting
 * some calendar variables with reference to the element involved.
 *
 * <span class="attrib">@param</span> ev
 *
 */</span>
Zapatec.Calendar.tableMouseOver = <span class="reserved">function</span> (ev) {
	var cal = Zapatec.Calendar.activeCalendar;
	<span class="reserved">if</span> (!cal) {
		<span class="reserved">return</span>;
	}
	var el = cal.activeDiv;
	var target = Zapatec.Utils.getTargetElement(ev);
	<span class="reserved">if</span> (target == el || target.parentNode == el) {
		<span class="comment">// Remove rowhilite for _keyEvents</span>
		<span class="reserved">if</span> (<span class="reserved">this</span>.lastRowHilite) {
			Zapatec.Utils.removeClass(<span class="reserved">this</span>.lastRowHilite, <span class="literal">"rowhilite"</span>);
			<span class="reserved">this</span>.lastRowHilite = null;
		}
		<span class="reserved">if</span> (!(el.navtype == 200 &amp;&amp; cal.closeButton) &amp;&amp; !(el.navtype == 400 &amp;&amp; cal.helpButton))
			Zapatec.Utils.addClass(el, <span class="literal">"hilite"</span>);
		Zapatec.Utils.addClass(el, <span class="literal">"active"</span>);
		<span class="reserved">if</span> (el.navtype != 50 &amp;&amp; el.navtype != 51)
			Zapatec.Utils.addClass(el.parentNode, <span class="literal">"rowhilite"</span>);
	} <span class="reserved">else</span> {
		<span class="reserved">if</span> (typeof el.navtype == <span class="literal">"undefined"</span> ||
			 ((el.navtype != 50 || el.navtype != 51) &amp;&amp; ((el.navtype == 0 &amp;&amp; !cal.histCombo) || Math.abs(el.navtype) &gt; 2)))
			Zapatec.Utils.removeClass(el, <span class="literal">"active"</span>);
		Zapatec.Utils.removeClass(el, <span class="literal">"hilite"</span>);
		Zapatec.Utils.removeClass(el.parentNode, <span class="literal">"rowhilite"</span>);
	}
	ev || (ev = window.event);
	<span class="reserved">if</span> ((el.navtype == 50 || el.navtype == 51) &amp;&amp; target != el) {
		var pos = Zapatec.Utils.getAbsolutePos(el);
		var w = el.offsetWidth;
		var x = ev.clientX;
		var dx;
		var decrease = true;
		<span class="reserved">if</span> (x &gt; pos.x + w) {
			dx = x - pos.x - w;
			decrease = false;
		} <span class="reserved">else</span>
			dx = pos.x - x;

		<span class="reserved">if</span> (dx &lt; 0) dx = 0;
		var range = el._range;
		var current = el._current;
		var date = null;
		var dateStart = null;
		<span class="reserved">if</span> (el.navtype == 51)
			dateStart = cal.currentDate;
		<span class="reserved">if</span> (dateStart)
			date = cal.currentDateEnd;
		<span class="reserved">else</span>
			date = cal.currentDate;

		var pm = (date.getHours() &gt;= 12);
		var old = el.firstChild.data;  <span class="comment">// old value of the element</span>
		var count = Math.floor(dx / 10) % range.length;
		<span class="reserved">for</span> (var i = range.length; --i &gt;= 0;)
			<span class="reserved">if</span> (range[i] == current)
				break;
		<span class="reserved">while</span> (count-- &gt; 0)
			<span class="reserved">if</span> (decrease) {
				<span class="reserved">if</span> (--i &lt; 0) {
					i = range.length - 1;
				}
			} <span class="reserved">else</span> <span class="reserved">if</span> (++i &gt;= range.length) {
				i = 0;
			}

		<span class="comment">//ALLOWED TIME CHECK</span>
		<span class="comment">//Current time is changing, check with the callback to see if it's in range of allowed times</span>
		<span class="comment">// Fills the "minute" and "hour" variables with the time that user wants to set, to pass them to the dateStatusHandler for verification.</span>
		<span class="comment">// As the script passes hours in 24 format, we need to convert input values if they are not in the needed format.</span>
		var minute = null; <span class="comment">// minutes to be passed</span>
		var hour = null; <span class="comment">// hours to be passed</span>
		var new_date = new Date(date); <span class="comment">// as we pass date element to the handler, we need to create new one and fill it with new minutes or hours (depending on what had changed)</span>
		<span class="comment">// if "ampm" was clicked</span>
		<span class="reserved">if</span> (el.className.indexOf(<span class="literal">"ampm"</span>, 0) != -1) {
			minute = date.getMinutes(); <span class="comment">// minutes didn't change</span>
			<span class="comment">// if the "ampm" value has changed we need to correct hours (add 12 or exclude 12 or set it to zero)</span>
			<span class="reserved">if</span> (old != range[i]) {
				hour = (range[i] == Zapatec.Calendar.i18n(<span class="literal">"pm"</span>, <span class="literal">"ampm"</span>, cal)) ? ((date.getHours() == 0) ? (12) : (date.getHours() + 12)) : (date.getHours() - 12);
			} <span class="reserved">else</span> {
				hour = date.getHours();
			}
			<span class="comment">// updates our new Date object that will be passed to the handler</span>
			new_date.setHours(hour);
		}
		<span class="comment">// if hours were clicked</span>
		<span class="reserved">if</span> (el.className.indexOf(<span class="literal">"hour"</span>, 0) != -1) {
			minute = date.getMinutes(); <span class="comment">// minutes didn't change</span>
			hour = (!cal.time24) ? ((pm) ? ((range[i] != 12) ? (parseInt(range[i], 10) + 12) : (12)) : ((range[i] != 12) ? (range[i]) : (0))) : (range[i]); <span class="comment">// new value of hours</span>
			new_date.setHours(hour);
		}
		<span class="comment">// if minutes were clicked</span>
		<span class="reserved">if</span> (el.className.indexOf(<span class="literal">"minute"</span>, 0) != -1) {
			hour = date.getHours(); <span class="comment">// hours didn't change</span>
			minute = range[i]; <span class="comment">// new value of minutes</span>
			new_date.setMinutes(minute);
		}

		var status = false;
		<span class="comment">// if the handler is set, we pass new values and retrieve result in "status" variable</span>
		<span class="reserved">if</span> (cal.getDateStatus) {
			status = cal.getDateStatus(new_date, date.getFullYear(), date.getMonth(), date.getDate(), parseInt(hour, 10), parseInt(minute, 10));
		}

		<span class="comment">// if time is enabled, we set new value</span>
		<span class="reserved">if</span> (status == false) {
			<span class="reserved">if</span> (!((!cal.time24) &amp;&amp; (range[i] == Zapatec.Calendar.i18n(<span class="literal">"pm"</span>, <span class="literal">"ampm"</span>, cal)) &amp;&amp; (hour &gt; 23))) {
				el.firstChild.data = range[i];
			}
		}

		cal.onUpdateTime();
		<span class="comment">//END OF ALLOWED TIME CHECK</span>
	}
	var mon = Zapatec.Calendar.findMonth(target);
	<span class="reserved">if</span> (mon) {
		<span class="reserved">if</span> (!mon.disabled) {
			<span class="reserved">if</span> (mon.month != cal.config.date.getMonth()) {
				<span class="reserved">if</span> (cal.hilitedMonth) {
					Zapatec.Utils.removeClass(cal.hilitedMonth, <span class="literal">"hilite"</span>);
				}
				Zapatec.Utils.addClass(mon, <span class="literal">"hilite"</span>);
				cal.hilitedMonth = mon;
			} <span class="reserved">else</span> <span class="reserved">if</span> (cal.hilitedMonth) {
				Zapatec.Utils.removeClass(cal.hilitedMonth, <span class="literal">"hilite"</span>);
			}
		}
	} <span class="reserved">else</span> {
		<span class="reserved">if</span> (cal.hilitedMonth) {
			Zapatec.Utils.removeClass(cal.hilitedMonth, <span class="literal">"hilite"</span>);
		}
		var year = Zapatec.Calendar.findYear(target);
		<span class="reserved">if</span> (year) {
			<span class="reserved">if</span> (year.year != cal.config.date.getFullYear()) {
				<span class="reserved">if</span> (cal.hilitedYear) {
					Zapatec.Utils.removeClass(cal.hilitedYear, <span class="literal">"hilite"</span>);
				}
				Zapatec.Utils.addClass(year, <span class="literal">"hilite"</span>);
				cal.hilitedYear = year;
			} <span class="reserved">else</span> <span class="reserved">if</span> (cal.hilitedYear) {
				Zapatec.Utils.removeClass(cal.hilitedYear, <span class="literal">"hilite"</span>);
			}
		} <span class="reserved">else</span> {
			<span class="reserved">if</span> (cal.hilitedYear) {
				Zapatec.Utils.removeClass(cal.hilitedYear, <span class="literal">"hilite"</span>);
			}
			var hist = Zapatec.Calendar.findHist(target);
			<span class="reserved">if</span> (hist) {
				<span class="reserved">if</span> (!Zapatec.Date.dateEqualsTo(hist.histDate, cal.config.date)) {
					<span class="reserved">if</span> (cal.hilitedHist) {
						Zapatec.Utils.removeClass(cal.hilitedHist, <span class="literal">"hilite"</span>);
					}
					Zapatec.Utils.addClass(hist, <span class="literal">"hilite"</span>);
					cal.hilitedHist = hist;
				} <span class="reserved">else</span> <span class="reserved">if</span> (cal.hilitedHist) {
					Zapatec.Utils.removeClass(cal.hilitedHist, <span class="literal">"hilite"</span>);
				}
			} <span class="reserved">else</span> <span class="reserved">if</span> (cal.hilitedHist) {
				Zapatec.Utils.removeClass(cal.hilitedHist, <span class="literal">"hilite"</span>);
			}
		}
	}

	<span class="reserved">return</span> Zapatec.Utils.stopEvent(ev);
};

<span class="comment">/**
 * \defgroup dndmove Drag'n'drop (move calendar) functions
 *
 * Contains some functions that implement calendar "drag'n'drop" facility which
 * allows one to move the calendar around the browser's view.
 */</span>
<span class="comment">//@{</span>
<span class="comment">/**
 * Called at mouseover and/or mousemove on document, this function repositions
 * the calendar according to the current mouse position.
 *
 * <span class="attrib">@param</span> ev [Event] The Event object
 * <span class="attrib">@return</span> false
 */</span>
Zapatec.Calendar.calDragIt = <span class="reserved">function</span> (ev) {
	ev || (ev = window.event);
	var cal = Zapatec.Calendar.activeCalendar;

	<span class="reserved">if</span> (!cal) {
		Zapatec.Caslendar.calDragEnd();
	}
	<span class="reserved">if</span> (!cal.config.disableDrag) {
		<span class="reserved">if</span> (!(cal &amp;&amp; cal.dragging)) {
			<span class="reserved">return</span> false;
		}
		var posX = ev.clientX + window.document.body.scrollLeft;
		var posY = ev.clientY + window.document.body.scrollTop;
		cal.hideShowCovered();
		var st = cal.element.style, L = posX - cal.xOffs, T = posY - cal.yOffs;
		st.left = L + <span class="literal">"px"</span>;
		st.top = T + <span class="literal">"px"</span>;
		Zapatec.Utils.setupWCH(cal.WCH, L, T);
	}
	<span class="reserved">return</span> Zapatec.Utils.stopEvent(ev);
};

<span class="comment">/**
 * Gets called when the drag and drop operation is finished; thus, at
 * "onmouseup".  This function unregisters D'n'D event handlers and calls
 * Zapatec.Calendar.hideShowCovered() which repaints as appropriate any
 * "windowed controls" that might have been hidden by the end user moving the
 * calendar. (note, this is only for IE5; for IE5.5 there are better--albeit
 * uglier--workarounds).
 *
 * <span class="attrib">@param</span> ev [Event] the event object
 * <span class="attrib">@return</span> false
 */</span>
Zapatec.Calendar.calDragEnd = <span class="reserved">function</span> (ev) {
	var cal = Zapatec.Calendar.activeCalendar;
	Zapatec.Utils.removeEvent(window.document, <span class="literal">"mousemove"</span>, Zapatec.Calendar.calDragIt);
	Zapatec.Utils.removeEvent(window.document, <span class="literal">"mouseover"</span>, Zapatec.Calendar.calDragIt);
	Zapatec.Utils.removeEvent(window.document, <span class="literal">"mouseup"</span>, Zapatec.Calendar.calDragEnd);
	<span class="reserved">if</span> (!cal) {
		<span class="reserved">return</span> false;
	}
	cal.dragging = false;
	Zapatec.Calendar.tableMouseUp(ev);
	cal.hideShowCovered();
};


<span class="comment">/**
 * Function for changig calendar size (used in IE)
 *
 * <span class="attrib">@private</span>
 * <span class="attrib">@param</span> {string} elementId - id of the changing element
 */</span>
Zapatec.Calendar._zoomIn = <span class="reserved">function</span> (elementId) {
	var oZoom = document.getElementById(elementId);
	var newZoom = parseInt(oZoom.style.zoom) + 10 + <span class="literal">'%'</span>
	oZoom.style.zoom = newZoom;
}

<span class="comment">/**
 * Function for changig calendar size (used in IE)
 *
 * <span class="attrib">@private</span>
 * <span class="attrib">@param</span> {string} elementId - id of the changing element
 */</span>
Zapatec.Calendar._zoomOut = <span class="reserved">function</span> (elementId) {
	var oZoom = document.getElementById(elementId);
	var newZoom = parseInt(oZoom.style.zoom) - 10 + <span class="literal">'%'</span>
	oZoom.style.zoom = newZoom;
}

<span class="comment">/**
 * Function for zoom in ie
 *
 * <span class="attrib">@private</span>
 * <span class="attrib">@param</span> {Object} event
 */</span>
Zapatec.Calendar.zoomElement = <span class="reserved">function</span> (event, elementId) {
	<span class="reserved">if</span> (!Zapatec.is_ie)
		<span class="reserved">return</span>;

	<span class="reserved">if</span> (!document.getElementById(elementId).style.zoom)
		document.getElementById(elementId).style.zoom = <span class="literal">"100%"</span>;
	var delta = 0;
	<span class="reserved">if</span> (!event) event = window.event;
	<span class="reserved">if</span> (event.wheelDelta) {
		delta = event.wheelDelta / 120;
		<span class="reserved">if</span> (window.opera) delta = -delta;
	} <span class="reserved">else</span> <span class="reserved">if</span> (event.detail) {
		delta = -event.detail / 3;
	}

	<span class="reserved">if</span> (delta &amp;&amp; event.ctrlKey) {
		<span class="reserved">if</span> (delta &gt; 0)
			Zapatec.Calendar._zoomOut(elementId);
		<span class="reserved">if</span> (delta &lt; 0)
			Zapatec.Calendar._zoomIn(elementId);
	}

	<span class="reserved">if</span> (event.preventDefault)
		event.preventDefault();
	event.returnValue = false;
}

<span class="comment">//@}</span>

<span class="comment">// END: CALENDAR STATIC FUNCTIONS</span>

<span class="comment">// BEGIN: CALENDAR OBJECT FUNCTIONS</span>

<span class="comment">/**
 * This function creates the calendar HTML elements inside the given parent.
 * If _par is null than it creates a popup calendar inside the BODY element.
 * If _par is an element, be it BODY, then it creates a non-popup calendar
 * (still hidden).
 *
 * The function looks rather complicated, but what it does is quite simple.
 * The basic calendar elements will be created, that is, a containing DIV, a
 * TABLE that contains a headers (titles, navigation bar and day names bars), a
 * body containing up to 12 months, each has 6 rows with 7 or 8 cells (this depends on whether week
 * numbers are on or off) and a footer containing the status bar.  Appropriate
 * event handlers are assigned to all buttons or to the titles and status bar
 * (for drag'n'drop).
 *
 * This function also builds the time selector if the calendar is configured
 * so, and it also creates the elements required for combo boxes (years,
 * months, history).
 *
 * This function does not display day names or dates.  This is done in
 * Zapatec.Calendar.prototype._init().  Therefore, by separating these 2
 * actions we can make date switching happen much faster because the _init
 * function will already have the elements in place (so we don't need to create
 * them again and again).  This was a major improvement which got in
 * the calendar v0.9.1.
 *
 * <span class="attrib">@param</span> _par
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.create = <span class="reserved">function</span> (_par) {
	var parent = null;
	<span class="reserved">if</span> (! _par) {
		<span class="comment">// default parent is the document body, in which case we create</span>
		<span class="comment">// a popup calendar.</span>
		var oInputField = <span class="reserved">this</span>.config.inputField;
		<span class="reserved">if</span> (oInputField) {
			parent = oInputField.parentNode;
		} <span class="reserved">else</span> {
			parent = window.document.getElementsByTagName(<span class="literal">"body"</span>)[0];
		}
		<span class="reserved">this</span>.isPopup = true;
		<span class="reserved">this</span>.WCH = Zapatec.Utils.createWCH(parent);
	} <span class="reserved">else</span> {
		parent = _par;
		<span class="reserved">this</span>.isPopup = false;
	}
	<span class="reserved">this</span>.currentDate = <span class="reserved">this</span>.config.date = <span class="reserved">this</span>.dateStr ? new Date(<span class="reserved">this</span>.dateStr) : new Date();
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeRange)
		<span class="reserved">this</span>.currentDateEnd = new Date(<span class="reserved">this</span>.currentDate);

	var rootTable = Zapatec.Utils.createElement(<span class="literal">"table"</span>);
	rootTable.cellSpacing = 0;
	rootTable.cellPadding = 0;
	rootTable.id = <span class="literal">"zpCalendar"</span> + <span class="reserved">this</span>.id + <span class="literal">"RootTable"</span>;
	rootTable.className = <span class="literal">'zpCalRootTable'</span>;
	<span class="reserved">this</span>.table = rootTable;
	Zapatec.Utils.createProperty(rootTable, <span class="literal">"calendar"</span>, <span class="reserved">this</span>);
	Zapatec.Utils.addEvent(rootTable, <span class="literal">"mousedown"</span>, Zapatec.Calendar.tableMouseDown);
	<span class="comment">//FIX for Opera's bug with row highlighting</span>
	<span class="reserved">if</span> (Zapatec.is_opera) {
		rootTable.style.width = (<span class="reserved">this</span>.config.monthsInRow * ((<span class="reserved">this</span>.config.weekNumbers) ? (8) : (7)) * 2 + 4.4 * <span class="reserved">this</span>.config.monthsInRow) + <span class="literal">"em"</span>;
	}

	var div = Zapatec.Utils.createElement(<span class="literal">"div"</span>);
	<span class="reserved">this</span>.element = div;
	<span class="reserved">this</span>.container = <span class="reserved">this</span>.element;
	div.className = <span class="literal">"calendar "</span> + <span class="reserved">this</span>.getClassName({prefix: <span class="literal">"zpCalendar"</span>}) + <span class="literal">" zpCalendar"</span> + <span class="reserved">this</span>.config.themeSize;

	div.id = <span class="literal">"zpCal"</span> + <span class="reserved">this</span>.id + <span class="literal">"Container"</span>;
	<span class="comment">// Set size for calendar in IE</span>
	<span class="reserved">if</span> (Zapatec.is_ie) {
		Zapatec.Utils.addEvent(div, <span class="literal">"mousewheel"</span>, new Function(<span class="literal">"Zapatec.Calendar.zoomElement(window.event,'"</span> + div.id + <span class="literal">"')"</span>));
	}

	<span class="reserved">if</span> (<span class="reserved">this</span>.isPopup) {
		div.style.position = <span class="literal">"absolute"</span>;
		div.style.display = <span class="literal">"none"</span>;
	}
	div.appendChild(rootTable);

	var cell = null;
	var row = null;

	var cal = <span class="reserved">this</span>;
	var hh = <span class="reserved">function</span> (text, cs, navtype, buttonType) {
		cell = Zapatec.Utils.createElement(<span class="literal">"td"</span>, row);
		<span class="reserved">if</span> (buttonType) {
			cell.id = <span class="literal">"zpCal"</span> + cal.id + buttonType + <span class="literal">"ButtonStatus"</span>;
		}
		cell.colSpan = cs;
		cell.className = <span class="literal">"button"</span>;
		<span class="reserved">if</span> (Math.abs(navtype) &lt;= 2)
			cell.className += <span class="literal">" nav"</span>;
		Zapatec.Calendar._add_evs(cell);
		Zapatec.Utils.createProperty(cell, <span class="literal">"calendar"</span>, cal);
		cell.navtype = navtype;
		<span class="reserved">if</span> (text.substr(0, 1) != <span class="literal">"&amp;"</span>) {
			cell.appendChild(document.createTextNode(text));
		}
		<span class="reserved">else</span> {
			<span class="comment">// FIXME: dirty hack for entities</span>
			cell.innerHTML = text;
		}
		<span class="reserved">return</span> cell;
	};
	var hd = <span class="reserved">function</span>(par, colspan, buttonType) {
		cell = Zapatec.Utils.createElement(<span class="literal">"td"</span>, par);
		<span class="reserved">if</span> (buttonType) {
			cell.id = <span class="literal">"zpCal"</span> + cal.id + buttonType + <span class="literal">"ButtonStatus"</span>;
		}
		cell.colSpan = colspan;
		cell.className = <span class="literal">"button"</span>;
		cell.innerHTML = <span class="literal">"&lt;div&gt;&amp;nbsp&lt;/div&gt;"</span>;
		<span class="reserved">return</span> cell;
	};

	<span class="comment">//Creating all the controls on the top</span>
	var title_length = ((<span class="reserved">this</span>.config.weekNumbers) ? (8) : (7)) * <span class="reserved">this</span>.config.monthsInRow - 2;

	var rootTbody = Zapatec.Utils.createElement(<span class="literal">"tbody"</span>, rootTable);
	var trOfRootTable = Zapatec.Utils.createElement(<span class="literal">"tr"</span>, rootTbody);
	trOfRootTable.id = <span class="literal">"zpCalendar"</span> + <span class="reserved">this</span>.id + <span class="literal">"RootTableTR1"</span>;
	var tdOfRootTable = Zapatec.Utils.createElement(<span class="literal">"td"</span>, trOfRootTable);
	tdOfRootTable.id = <span class="literal">"zpCalendar"</span> + <span class="reserved">this</span>.id + <span class="literal">"RootTableTR1TD1"</span>;
	tdOfRootTable.className = <span class="literal">"RootTableTD"</span>;
	var table = Zapatec.Utils.createElement(<span class="literal">"table"</span>, tdOfRootTable);
	table.id = <span class="literal">"zpCalendar"</span> + <span class="reserved">this</span>.id + <span class="literal">"Calendar1RootContainer"</span>;
	table.className = <span class="literal">'zpCalTable'</span>;
	table.cellSpacing = 0;
	table.cellPadding = 0;
	var thead = Zapatec.Utils.createElement(<span class="literal">"thead"</span>, table);
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.numberMonths == 1) {
		<span class="reserved">this</span>.title = thead;
	} <span class="reserved">else</span> {
		thead.style.display = <span class="literal">'none'</span>;
	}

	row = Zapatec.Utils.createElement(<span class="literal">"tr"</span>, thead);
	var help_length = 0, close_length = 0;

	<span class="reserved">if</span> (!<span class="reserved">this</span>.config.minimal) {
		<span class="reserved">if</span> (<span class="reserved">this</span>.config.closeButton || <span class="reserved">this</span>.config.helpButton) {
			<span class="comment">// Set buttons</span>
			cell = Zapatec.Utils.createElement(<span class="literal">"td"</span>, row);
			cell.colSpan = title_length + 2;
			var table1 = Zapatec.Utils.createElement(<span class="literal">"table"</span>, cell);
			table1.style.border = <span class="literal">"none"</span>;
			table1.width = <span class="literal">"100%"</span>;
			table1.cellPadding = 0;
			table1.cellSpacing = 0;
			table1 = Zapatec.Utils.createElement(<span class="literal">"tbody"</span>, table1);
			row = Zapatec.Utils.createElement(<span class="literal">"tr"</span>, table1);
			row.vAlign = <span class="literal">"middle"</span>;
		}
		<span class="reserved">if</span> (!<span class="reserved">this</span>.config.noHelp) {
			<span class="reserved">if</span> (<span class="reserved">this</span>.config.helpButton) {
				var calendarHelpButton = hh(<span class="reserved">this</span>.config.helpButton ? <span class="literal">""</span> : <span class="literal">"?"</span>, 1, 400, <span class="literal">"Help"</span>);
				calendarHelpButton.appendChild(<span class="reserved">this</span>.helpButton.getContainer());
				<span class="reserved">if</span> (<span class="reserved">this</span>.helpButton.getContainer().style.width)
					help_length = <span class="reserved">this</span>.helpButton.getContainer().style.width;
				<span class="reserved">if</span> (<span class="reserved">this</span>.helpButton.img.width)
					help_length = <span class="reserved">this</span>.helpButton.img.width;
			} <span class="reserved">else</span> {
				var calendarHelpButton = hh(<span class="reserved">this</span>.config.helpButton ? <span class="literal">""</span> : <span class="literal">"?"</span>, 1, 400, <span class="literal">"Help"</span>);
			}
			calendarHelpButton.ttip = Zapatec.Calendar.i18n(<span class="literal">"INFO"</span>, null, <span class="reserved">this</span>);
		} <span class="reserved">else</span> {
			hd(row, 1, <span class="literal">"Help"</span>);
		}
		<span class="reserved">this</span>.title = hh(<span class="literal">"&amp;nbsp;"</span>, title_length, 300);
		<span class="reserved">this</span>.title.className = <span class="literal">"title"</span>;
		<span class="reserved">this</span>.title.id = <span class="literal">"zpCal"</span> + <span class="reserved">this</span>.id + <span class="literal">"Title"</span>;
		<span class="reserved">if</span> (<span class="reserved">this</span>.isPopup) {
			<span class="reserved">if</span> (!<span class="reserved">this</span>.config.disableDrag) {
				<span class="reserved">this</span>.title.ttip = Zapatec.Calendar.i18n(<span class="literal">"DRAG_TO_MOVE"</span>, null, <span class="reserved">this</span>);
				<span class="reserved">this</span>.title.style.cursor = <span class="literal">"move"</span>;
			}
			<span class="reserved">if</span> (!<span class="reserved">this</span>.config.noCloseButton) {
				<span class="reserved">if</span> (<span class="reserved">this</span>.config.closeButton) {
					var calendarCloseButton = hh(<span class="reserved">this</span>.config.closeButton ? <span class="literal">""</span> : <span class="literal">"&amp;#x00d7;"</span>, 1, 200, <span class="literal">"Close"</span>);
					calendarCloseButton.appendChild(<span class="reserved">this</span>.closeButton.getContainer());
					<span class="reserved">if</span> (<span class="reserved">this</span>.closeButton.getContainer().style.width)
						close_length = <span class="reserved">this</span>.closeButton.getContainer().style.width;
					<span class="reserved">if</span> (<span class="reserved">this</span>.closeButton.img.width)
						close_length = <span class="reserved">this</span>.closeButton.img.width;
				} <span class="reserved">else</span> {
					var calendarCloseButton = hh(<span class="reserved">this</span>.config.closeButton ? <span class="literal">""</span> : <span class="literal">"&amp;#x00d7;"</span>, 1, 200, <span class="literal">"Close"</span>);
				}
				calendarCloseButton.ttip = Zapatec.Calendar.i18n(<span class="literal">"CLOSE"</span>, null, <span class="reserved">this</span>);
			} <span class="reserved">else</span> {
				hd(row, 1, <span class="literal">"Close"</span>);
			}
		} <span class="reserved">else</span> {
			hd(row, 1, <span class="literal">"Close"</span>);
		}
		<span class="reserved">if</span> (help_length &gt; 0 || close_length &gt; 0) {
			calendarHelpButton.width = calendarCloseButton.width = Math.max(help_length, close_length);
		}

		row = Zapatec.Utils.createElement(<span class="literal">"tr"</span>, thead);
		<span class="reserved">this</span>._nav_py = hh(<span class="literal">"&amp;#x00ab;"</span>, 1, -2, <span class="literal">"PrevYear"</span>);
		<span class="reserved">this</span>._nav_py.ttip = Zapatec.Calendar.i18n(<span class="literal">"PREV_YEAR"</span>, null, <span class="reserved">this</span>);
		<span class="reserved">this</span>._nav_pm = hh(<span class="literal">"&amp;#x2039;"</span>, 1, -1, <span class="literal">"PrevMonth"</span>);
		<span class="reserved">this</span>._nav_pm.ttip = Zapatec.Calendar.i18n(<span class="literal">"PREV_MONTH"</span>, null, <span class="reserved">this</span>);
		<span class="reserved">this</span>._nav_now = hh(Zapatec.Calendar.i18n(<span class="literal">"TODAY"</span>, null, <span class="reserved">this</span>), title_length - 2, 0, <span class="literal">"Today"</span>);
		<span class="reserved">this</span>._nav_now.ttip = Zapatec.Calendar.i18n(<span class="literal">"GO_TODAY"</span>, null, <span class="reserved">this</span>);
		<span class="reserved">this</span>._nav_nm = hh(<span class="literal">"&amp;#x203a;"</span>, 1, 1, <span class="literal">"NextMonth"</span>);
		<span class="reserved">this</span>._nav_nm.ttip = Zapatec.Calendar.i18n(<span class="literal">"NEXT_MONTH"</span>, null, <span class="reserved">this</span>);
		<span class="reserved">this</span>._nav_ny = hh(<span class="literal">"&amp;#x00bb;"</span>, 1, 2, <span class="literal">"NextYear"</span>);
		<span class="reserved">this</span>._nav_ny.ttip = Zapatec.Calendar.i18n(<span class="literal">"NEXT_YEAR"</span>, null, <span class="reserved">this</span>);

	} <span class="reserved">else</span> {
		<span class="reserved">this</span>._nav_py = {disabled:true};
		<span class="reserved">this</span>._nav_ny = {disabled:true};

		<span class="reserved">if</span> (<span class="reserved">this</span>.config.hideNavPanel) {
			<span class="reserved">this</span>._nav_pm = {disabled:true};
			<span class="reserved">this</span>.title = {disabled:true};
			<span class="reserved">this</span>._nav_nm = {disabled:true};
		} <span class="reserved">else</span> {
			<span class="reserved">this</span>._nav_pm = hh(<span class="literal">"&amp;#x2039;"</span>, 1, -1, <span class="literal">"PrevMonth"</span>);
			<span class="reserved">this</span>._nav_pm.ttip = Zapatec.Calendar.i18n(<span class="literal">"PREV_MONTH"</span>, null, <span class="reserved">this</span>);
			<span class="reserved">this</span>.title = hh(<span class="literal">"&amp;nbsp;"</span>, title_length, 300);
			<span class="reserved">this</span>.title.className = <span class="literal">"title"</span>;
			<span class="reserved">this</span>.title.id = <span class="literal">"zpCal"</span> + <span class="reserved">this</span>.id + <span class="literal">"Title"</span>;
			<span class="reserved">if</span> (<span class="reserved">this</span>.isPopup) {
				<span class="reserved">if</span> (!<span class="reserved">this</span>.config.disableDrag) {
					<span class="reserved">this</span>.title.ttip = Zapatec.Calendar.i18n(<span class="literal">"DRAG_TO_MOVE"</span>, null, <span class="reserved">this</span>);
					<span class="reserved">this</span>.title.style.cursor = <span class="literal">"move"</span>;
				}
			}
			<span class="reserved">this</span>._nav_nm = hh(<span class="literal">"&amp;#x203a;"</span>, 1, 1, <span class="literal">"NextMonth"</span>);
			<span class="reserved">this</span>._nav_nm.ttip = Zapatec.Calendar.i18n(<span class="literal">"NEXT_MONTH"</span>, null, <span class="reserved">this</span>);
		}
	}


	<span class="comment">//Here we calculate the number of rows for multimonth calendar</span>
	var rowsOfMonths = Math.floor(<span class="reserved">this</span>.config.numberMonths / <span class="reserved">this</span>.config.monthsInRow);
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.numberMonths % <span class="reserved">this</span>.config.monthsInRow &gt; 0) {
		++rowsOfMonths;
	}
	<span class="comment">//Every iteration of this cycle creates a row of months in the calendar</span>
	var iId = <span class="reserved">this</span>.id;
	var oConfig = <span class="reserved">this</span>.config;
	var iMonths = oConfig.numberMonths;
	var iMonthInRow = oConfig.monthsInRow;
	var bHideNavPanel = oConfig.hideNavPanel;
	<span class="reserved">for</span> (var l = 1; l &lt;= rowsOfMonths; ++l) {
		<span class="reserved">if</span> (l &gt; 1) {
			trOfRootTable = Zapatec.Utils.createElement(<span class="literal">"tr"</span>, rootTbody);
			trOfRootTable.id = <span class="literal">"zpCalendar"</span> + <span class="reserved">this</span>.id + <span class="literal">"RootTableMarginTR"</span> + (l - 1);
			trOfRootTable.className = <span class="literal">"marginTR"</span>;
			<span class="comment">// creating td that will be a "margin"</span>
			tdOfRootTable = Zapatec.Utils.createElement(<span class="literal">"td"</span>, trOfRootTable);
			tdOfRootTable.id = <span class="literal">"zpCalendar"</span> + <span class="reserved">this</span>.id + <span class="literal">"RootTableMarginTR"</span> + (l - 1) + <span class="literal">"TD"</span> + (l - 1);
			tdOfRootTable.className = <span class="literal">"marginTD"</span>;
			trOfRootTable = Zapatec.Utils.createElement(<span class="literal">"tr"</span>, rootTbody);
			trOfRootTable.id = <span class="literal">"zpCalendar"</span> + <span class="reserved">this</span>.id + <span class="literal">"RootTableTR"</span> + l;
			tdOfRootTable = Zapatec.Utils.createElement(<span class="literal">"td"</span>, trOfRootTable);
			tdOfRootTable.id = <span class="literal">"zpCalendar"</span> + <span class="reserved">this</span>.id + <span class="literal">"RootTableTR"</span> + l + <span class="literal">"TD"</span> + l;
			tdOfRootTable.className = <span class="literal">"RootTableTD"</span> + l;
			table = Zapatec.Utils.createElement(<span class="literal">"table"</span>, tdOfRootTable);
			table.id = <span class="literal">"zpCalendar"</span> + <span class="reserved">this</span>.id + <span class="literal">"Calendar"</span> + l + <span class="literal">"RootContainer"</span>;
			table.className = <span class="literal">'zpCalTable'</span>;
			table.cellSpacing = 0;
			table.cellPadding = 0;
		}
		var thead = Zapatec.Utils.createElement(<span class="literal">"thead"</span>, table);
		<span class="comment">//Fix for the Operas bug, this is a workaround which makes Opera display THEAD elements as TBODY el.</span>
		<span class="comment">//The problem is that Opera displays all the THEAD elements in the table first, and only then TBODY elements (an ugly look!).</span>
		<span class="reserved">if</span> (Zapatec.is_opera) {
			thead.style.display = <span class="literal">"table-row-group"</span>;
		}
		<span class="reserved">if</span> (iMonths != 1) {
			row = zapatecUtils.createElement(<span class="literal">"tr"</span>, thead);
			row.className = <span class="literal">"rowSubTitleContainer"</span>;
			var title_length = 5;
			oConfig.weekNumbers &amp;&amp; ++title_length;
			<span class="comment">//creating the titles for the months</span>
			<span class="reserved">this</span>.titles[l] = new Array();
			<span class="reserved">for</span> (var k = 1; (k &lt;= iMonthInRow) &amp;&amp; ((l - 1) * iMonthInRow + k &lt;= iMonths); ++k) {
				<span class="reserved">if</span> (bHideNavPanel) {
					<span class="reserved">if</span> (l == 1) {
						cell = zapatecUtils.createElement(<span class="literal">"td"</span>, row);
						cell.colSpan = 1;
						cell.className = <span class="literal">"zpCalPrevMonth"</span>;
						cell.navtype = -1;
						<span class="reserved">this</span>._nav_pm = {navtype: -1, calendar: <span class="reserved">this</span>, className: <span class="literal">""</span>};
						cell.onclick = <span class="reserved">function</span>() {
							zapatecCalendar.cellClick(cal._nav_pm)
						};
						cell.innerHTML = <span class="literal">'&lt;div class="zpCalPrevMonthArrow"&gt;&lt;/div&gt;'</span>;
						<span class="reserved">this</span>.titles[l][k] = hh(<span class="literal">"&amp;nbsp;"</span>, title_length, 300);
						<span class="reserved">this</span>.titles[l][k].className = <span class="literal">"title"</span>;
						<span class="reserved">this</span>.titles[l][k].id = <span class="literal">"zpCal"</span> + iId + <span class="literal">"SubTitle"</span> + ((l - 1) * iMonthInRow + k);
						cell = zapatecUtils.createElement(<span class="literal">"td"</span>, row);
						cell.colSpan = 1;
						cell.className = <span class="literal">"zpCalNextMonth"</span>;
						<span class="reserved">this</span>._nav_nm = {navtype: 1, calendar: <span class="reserved">this</span>, className: <span class="literal">""</span>};
						cell.onclick = <span class="reserved">function</span>() {
							zapatecCalendar.cellClick(cal._nav_nm)
						};
						cell.innerHTML = <span class="literal">'&lt;div class="zpCalNextMonthArrow"&gt;&lt;/div&gt;'</span>;
					} <span class="reserved">else</span> {
						<span class="reserved">this</span>.titles[l][k] = hh(<span class="literal">"&amp;nbsp;"</span>, title_length + 2, 300);
						<span class="reserved">this</span>.titles[l][k].className = <span class="literal">"title"</span>;
						<span class="reserved">this</span>.titles[l][k].id = <span class="literal">"zpCal"</span> + iId + <span class="literal">"SubTitle"</span> + ((l - 1) * iMonthInRow + k);
					}
				} <span class="reserved">else</span> {
					hd(row, 1);
					<span class="reserved">this</span>.titles[l][k] = hh(<span class="literal">"&amp;nbsp;"</span>, title_length, 300);
					<span class="reserved">this</span>.titles[l][k].className = <span class="literal">"title"</span>;
					<span class="reserved">this</span>.titles[l][k].id = <span class="literal">"zpCal"</span> + iId + <span class="literal">"SubTitle"</span> + ((l - 1) * iMonthInRow + k);
					hd(row, 1);
				}
			}
		}
		<span class="comment">// day names</span>
		row = Zapatec.Utils.createElement(<span class="literal">"tr"</span>, thead);
		row.className = <span class="literal">"daynames"</span>;
		<span class="reserved">for</span> (k = 1; (k &lt;= <span class="reserved">this</span>.config.monthsInRow) &amp;&amp; ((l - 1) * <span class="reserved">this</span>.config.monthsInRow + k &lt;= <span class="reserved">this</span>.config.numberMonths); ++k) {
			<span class="reserved">if</span> (<span class="reserved">this</span>.config.weekNumbers) {
				cell = Zapatec.Utils.createElement(<span class="literal">"td"</span>, row);
				cell.className = <span class="literal">"name wn"</span>;
				cell.appendChild(window.document.createTextNode(Zapatec.Calendar.i18n(<span class="literal">"WK"</span>, null, <span class="reserved">this</span>)));
				<span class="reserved">if</span> (k &gt; 1) {
					Zapatec.Utils.addClass(cell, <span class="literal">"month-left-border"</span>);
				}
				var cal_wk = Zapatec.Calendar.i18n(<span class="literal">"WK"</span>, null, <span class="reserved">this</span>)
				<span class="reserved">if</span> (cal_wk == null) {
					<span class="comment">//if it's not defined in the language file, leave it blank</span>
					cal_wk = <span class="literal">""</span>;
				}

			}
			<span class="comment">//week day names cells</span>
			<span class="reserved">for</span> (var i = 7; i &gt; 0; --i) {
				cell = Zapatec.Utils.createElement(<span class="literal">"td"</span>, row);
				cell.appendChild(document.createTextNode(<span class="literal">"&amp;nbsp;"</span>));
				cell.id = <span class="literal">"zpCal"</span> + <span class="reserved">this</span>.id + <span class="literal">"WeekDayButton"</span> + (7 - i) + <span class="literal">"Status"</span>;
			}
		}
		<span class="reserved">this</span>.firstDayName = row.childNodes[<span class="reserved">this</span>.config.weekNumbers ? 1 : 0];
		<span class="reserved">this</span>.rowsOfDayNames[l] = <span class="reserved">this</span>.firstDayName;
		<span class="reserved">this</span>._displayWeekdays();

		var tbody = Zapatec.Utils.createElement(<span class="literal">"tbody"</span>, table);
		<span class="reserved">this</span>.tbody[l] = tbody;

		<span class="reserved">for</span> (i = 6; i &gt; 0; --i) {
			<span class="comment">//creating a row of days for all the months in the row</span>
			row = Zapatec.Utils.createElement(<span class="literal">"tr"</span>, tbody);
			<span class="reserved">for</span> (k = 1; (k &lt;= <span class="reserved">this</span>.config.monthsInRow) &amp;&amp; ((l - 1) * <span class="reserved">this</span>.config.monthsInRow + k &lt;= <span class="reserved">this</span>.config.numberMonths); ++k) {
				<span class="reserved">if</span> (<span class="reserved">this</span>.config.weekNumbers) {
					cell = Zapatec.Utils.createElement(<span class="literal">"td"</span>, row);
					cell.id = <span class="literal">"zpCal"</span> + <span class="reserved">this</span>.id + <span class="literal">"WeekNumber"</span> + (6 - i);
					<span class="reserved">if</span> (typeof <span class="reserved">this</span>.config.onWeekClick == <span class="literal">"function"</span>) {
						cell.navtype = 150;
						cell.calendar = <span class="reserved">this</span>;
						cell.value = k;
						Zapatec.Calendar._add_evs(cell);
					}
					cell.appendChild(document.createTextNode(<span class="literal">"&amp;nbsp;"</span>));
				}
				<span class="reserved">for</span> (var j = 7; j &gt; 0; --j) {
					cell = Zapatec.Utils.createElement(<span class="literal">"td"</span>, row);
					cell.id = <span class="literal">"zpCal"</span> + <span class="reserved">this</span>.id + <span class="literal">"DateCell"</span> + ((l - 1) * <span class="reserved">this</span>.config.monthsInRow + k) + <span class="literal">"-"</span> + (6 - i) + <span class="literal">"-"</span> + (7 - j);
					cell.appendChild(document.createTextNode(<span class="literal">"&amp;nbsp;"</span>));
					Zapatec.Utils.createProperty(cell, <span class="literal">"calendar"</span>, <span class="reserved">this</span>);
					Zapatec.Calendar._add_evs(cell);
				}
			}
		}
	}

	var tfoot = Zapatec.Utils.createElement(<span class="literal">"tfoot"</span>, table);

	<span class="reserved">if</span> (<span class="reserved">this</span>.config.showsTime) {
		row = Zapatec.Utils.createElement(<span class="literal">"tr"</span>, tfoot);
		row.className = <span class="literal">"time"</span>;
		<span class="comment">//empty area for positioning the time controls under the control month</span>
		var emptyColspan;
		<span class="reserved">if</span> (<span class="reserved">this</span>.config.monthsInRow != 1) {
			cell = Zapatec.Utils.createElement(<span class="literal">"td"</span>, row);
			emptyColspan = cell.colSpan = Math.ceil((((<span class="reserved">this</span>.config.weekNumbers) ? 8 : 7) * (<span class="reserved">this</span>.config.monthsInRow - 1)) / 2);
			<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeRange) cell.rowSpan = 2;
			cell.className = <span class="literal">"timetext"</span>;
			cell.innerHTML = <span class="literal">"&amp;nbsp"</span>;
		}

		cell = Zapatec.Utils.createElement(<span class="literal">"td"</span>, row);
		cell.className = <span class="literal">"timetext"</span>;
		cell.colSpan = <span class="reserved">this</span>.config.weekNumbers ? 2 : 1;
		<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeRange)
			cell.rowSpan = 2;
		cell.innerHTML = Zapatec.Calendar.i18n(<span class="literal">"TIME"</span>, null, <span class="reserved">this</span>) || <span class="literal">"&amp;nbsp;"</span>;
		var firstrow = row;
		<span class="comment">// For later "TIME_PART" init (ex.2)</span>
		Zapatec.Calendar.activeCalendar = <span class="reserved">this</span>;

		(<span class="reserved">function</span>() {
			<span class="reserved">function</span> makeTimePart(className, partId, init, range_start, range_end, timeRange) {
				var table, tbody, tr, tr2, part;
				<span class="reserved">if</span> (range_end) {
					cell = Zapatec.Utils.createElement(<span class="literal">"td"</span>, row);
					cell.colSpan = 1;
					<span class="reserved">if</span> (cal.config.showsTime != <span class="literal">"seconds"</span>) {
						++cell.colSpan;
					}
					cell.className = <span class="literal">"parent-"</span> + className;
					table = Zapatec.Utils.createElement(<span class="literal">"table"</span>, cell);
					table.cellSpacing = table.cellPadding = 0;
					<span class="reserved">if</span> (className == <span class="literal">"hour"</span>)
						table.align = <span class="literal">"right"</span>;
					table.className = <span class="literal">"calendar-time-scroller"</span>;
					tbody = Zapatec.Utils.createElement(<span class="literal">"tbody"</span>, table);
					tr = Zapatec.Utils.createElement(<span class="literal">"tr"</span>, tbody);
					tr2 = Zapatec.Utils.createElement(<span class="literal">"tr"</span>, tbody);
					<span class="reserved">if</span> (timeRange) cell.style.border = <span class="literal">"none"</span>;
				} <span class="reserved">else</span>
					tr = row;
				part = Zapatec.Utils.createElement(<span class="literal">"td"</span>, tr);
				part.className = className;
				part.id = <span class="literal">"zpTime"</span> + cal.id + partId + <span class="literal">"SelectStatus"</span>;
				part.appendChild(window.document.createTextNode(init &lt; 10 ? <span class="literal">'0'</span> + init : init));
				Zapatec.Utils.createProperty(part, <span class="literal">"calendar"</span>, cal);
				part.ttip = Zapatec.Calendar.i18n(<span class="literal">"TIME_PART"</span>, null);
				part.navtype = 50;
				<span class="reserved">if</span> (cal.config.timeRange &amp;&amp; partId.substr(partId.length - 1) == <span class="literal">'1'</span>)
					part.navtype = 51;
				part._range = [];
				<span class="reserved">if</span> (!range_end)
					part._range = range_start &lt; 10 ? <span class="literal">'0'</span> + range_start : range_start;
				<span class="reserved">else</span> {
					part.rowSpan = 2;
					<span class="reserved">for</span> (var i = range_start; i &lt;= range_end; ++i) {
						var txt;
						<span class="reserved">if</span> (i &lt; 10 &amp;&amp; range_end &gt;= 10) txt = <span class="literal">'0'</span> + i;
						<span class="reserved">else</span> txt = <span class="literal">''</span> + i;
						part._range[part._range.length] = txt;
					}
					var up = Zapatec.Utils.createElement(<span class="literal">"td"</span>, tr);
					up.className = <span class="literal">"up"</span>;
					up.navtype = 201;
					<span class="reserved">if</span> (cal.config.timeRange &amp;&amp; partId.substr(partId.length - 1) == <span class="literal">'1'</span>)
						up.navtype = 211;
					up.id = <span class="literal">"zpTime"</span> + cal.id + partId + <span class="literal">"UpButtonStatus"</span>;
					Zapatec.Utils.createProperty(up, <span class="literal">"calendar"</span>, cal);
					up.timePart = part;
					<span class="reserved">if</span> (Zapatec.is_khtml)
						up.innerHTML = <span class="literal">"&amp;nbsp;"</span>;
					Zapatec.Calendar._add_evs(up);

					var down = Zapatec.Utils.createElement(<span class="literal">"td"</span>, tr2);
					down.className = <span class="literal">"down"</span>;
					down.navtype = 202;
					<span class="reserved">if</span> (cal.config.timeRange &amp;&amp; partId.substr(partId.length - 1) == <span class="literal">'1'</span>)
						down.navtype = 212;
					down.id = <span class="literal">"zpTime"</span> + cal.id + partId + <span class="literal">"DownButtonStatus"</span>;
					Zapatec.Utils.createProperty(down, <span class="literal">"calendar"</span>, cal);
					down.timePart = part;
					<span class="reserved">if</span> (Zapatec.is_khtml)
						down.innerHTML = <span class="literal">"&amp;nbsp;"</span>;
					Zapatec.Calendar._add_evs(down);
				}
				Zapatec.Calendar._add_evs(part);
				<span class="reserved">return</span> part;
			}
			;


			var hrs = cal.currentDate.getHours();
			var mins = cal.currentDate.getMinutes();
			<span class="reserved">if</span> (cal.config.showsTime == <span class="literal">"seconds"</span>) {
				var secs = cal.currentDate.getSeconds();
			}
			var t12 = !cal.time24;
			var pm = (hrs &gt; 12);
			<span class="reserved">if</span> (t12 &amp;&amp; pm) hrs -= 12;
			var H = makeTimePart(<span class="literal">"hour"</span>, <span class="literal">"Hours"</span>, hrs, t12 ? 1 : 0, t12 ? 12 : 23);
			<span class="comment">//calculating of the step for hours</span>
			H._step = (cal.config.timeInterval &gt; 30) ? (cal.config.timeInterval / 60) : 1;
			cell = Zapatec.Utils.createElement(<span class="literal">"td"</span>, row);
			cell.innerHTML = <span class="literal">":"</span>;
			cell.className = <span class="literal">"colon"</span>;
			var M = makeTimePart(<span class="literal">"minute"</span>, <span class="literal">"Minutes"</span>, mins, 0, 59);
			<span class="comment">//calculating of the step for minutes</span>
			M._step = ((cal.config.timeInterval) &amp;&amp; (cal.config.timeInterval &lt; 60)) ? (cal.config.timeInterval) : 5; <span class="comment">// FIXME: make this part configurable</span>
			<span class="reserved">if</span> (cal.config.showsTime == <span class="literal">"seconds"</span>) {
				cell = Zapatec.Utils.createElement(<span class="literal">"td"</span>, row);
				cell.innerHTML = <span class="literal">":"</span>;
				cell.className = <span class="literal">"colon"</span>;
				var S = makeTimePart(<span class="literal">"minute"</span>, <span class="literal">"Seconds"</span>, secs, 0, 59);
				S._step = 5;
			}
			var AP = null;
			<span class="reserved">if</span> (t12) {
				AP = makeTimePart(<span class="literal">"ampm"</span>, <span class="literal">"AMPM"</span>, pm ? Zapatec.Calendar.i18n(<span class="literal">"pm"</span>, <span class="literal">"ampm"</span>, cal) : Zapatec.Calendar.i18n(<span class="literal">"am"</span>, <span class="literal">"ampm"</span>, cal), [Zapatec.Calendar.i18n(<span class="literal">"am"</span>, <span class="literal">"ampm"</span>, cal), Zapatec.Calendar.i18n(<span class="literal">"pm"</span>, <span class="literal">"ampm"</span>, cal)]);
				AP.className += <span class="literal">" button"</span>;
				<span class="comment">//if (cal.config.timeRange) AP.style.borderBottom = "none";</span>
			} <span class="reserved">else</span> {
				AP = Zapatec.Utils.createElement(<span class="literal">"td"</span>, row).innerHTML = <span class="literal">"&amp;nbsp;"</span>;
			}

			<span class="reserved">if</span> (cal.config.timeRange) {

				row = Zapatec.Utils.createElement(<span class="literal">"tr"</span>, tfoot);
				row.className = <span class="literal">"time"</span>;

				hrs = cal.currentDateEnd.getHours();
				mins = cal.currentDateEnd.getMinutes();
				<span class="reserved">if</span> (cal.showsTime == <span class="literal">"seconds"</span>) {
					secs = cal.currentDateEnd.getSeconds();
				}
				t12 = !cal.time24;
				pm = (hrs &gt; 12);
				<span class="reserved">if</span> (t12 &amp;&amp; pm) hrs -= 12;
				var H1 = makeTimePart(<span class="literal">"hour"</span>, <span class="literal">"Hours1"</span>, hrs, t12 ? 1 : 0, t12 ? 12 : 23, cal.config.timeRange);
				<span class="comment">//calculating of the step for hours</span>
				H1._step = (cal.config.timeInterval &gt; 30) ? (cal.config.timeInterval / 60) : 1;
				cell = Zapatec.Utils.createElement(<span class="literal">"td"</span>, row);
				cell.innerHTML = <span class="literal">":"</span>;
				cell.className = <span class="literal">"colon"</span>;
				cell.style.border = <span class="literal">"none"</span>;
				var M1 = makeTimePart(<span class="literal">"minute"</span>, <span class="literal">"Minutes1"</span>, mins, 0, 59, cal.config.timeRange);
				<span class="comment">//calculating of the step for minutes</span>
				M1._step = ((cal.config.timeInterval) &amp;&amp; (cal.config.timeInterval &lt; 60)) ? (cal.config.timeInterval) : 5; <span class="comment">// FIXME: make this part configurable</span>
				<span class="reserved">if</span> (cal.config.showsTime == <span class="literal">"seconds"</span>) {
					cell = Zapatec.Utils.createElement(<span class="literal">"td"</span>, row);
					cell.innerHTML = <span class="literal">":"</span>;
					cell.className = <span class="literal">"colon"</span>;
					cell.style.border = <span class="literal">"none"</span>;
					var S1 = makeTimePart(<span class="literal">"minute"</span>, <span class="literal">"Seconds1"</span>, secs, 0, 59, cal.config.timeRange);
					S1._step = 5;
				}
				var AP1 = null
				<span class="reserved">if</span> (t12) {
					AP1 = makeTimePart(<span class="literal">"ampm"</span>, <span class="literal">"AMPM1"</span>, pm ? Zapatec.Calendar.i18n(<span class="literal">"pm"</span>, <span class="literal">"ampm"</span>, cal) : Zapatec.Calendar.i18n(<span class="literal">"am"</span>, <span class="literal">"ampm"</span>, cal), [Zapatec.Calendar.i18n(<span class="literal">"am"</span>, <span class="literal">"ampm"</span>, cal), Zapatec.Calendar.i18n(<span class="literal">"pm"</span>, <span class="literal">"ampm"</span>, cal)], false, cal.config.timeRange);
					AP1.className += <span class="literal">" button"</span>;
					<span class="comment">//if (cal.config.timeRange) AP1.style.borderTop = "none";</span>
				} <span class="reserved">else</span> {
					AP1 = Zapatec.Utils.createElement(<span class="literal">"td"</span>, row).innerHTML = <span class="literal">"&amp;nbsp;"</span>;
				}
			}

			cal.onSetTime = <span class="reserved">function</span>(currentDate) {
				var dateStartH = dateStartM = null;
				var thisH = H;
				var thisM = M;
				var thisS = S;
				var thisAP = AP;
				<span class="reserved">if</span> (!currentDate) {
					currentDate = <span class="reserved">this</span>.currentDate;
				}
				<span class="reserved">else</span> {
					dateStartH = <span class="reserved">this</span>.currentDate.getHours();
					dateStartM = <span class="reserved">this</span>.currentDate.getMinutes();
					thisH = H1;
					thisM = M1;
					thisS = S1;
					thisAP = AP1;
				}

				var hrs = currentDate.getHours();
				var mins = currentDate.getMinutes();
				<span class="reserved">if</span> (<span class="reserved">this</span>.config.showsTime == <span class="literal">"seconds"</span>) {
					var secs = cal.currentDate.getSeconds();
				}
				<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeInterval) {
					mins += <span class="reserved">this</span>.config.timeInterval - ((mins - 1 + <span class="reserved">this</span>.config.timeInterval) % <span class="reserved">this</span>.config.timeInterval) - 1;
				}
				<span class="reserved">while</span> (mins &gt;= 60) {
					mins -= 60;
					++hrs;
				}
				<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeInterval &gt; 60) {
					var interval = <span class="reserved">this</span>.config.timeInterval / 60;
					<span class="reserved">if</span> (hrs % interval != 0) {
						hrs += interval - ((hrs - 1 + interval) % interval) - 1;
					}
					<span class="reserved">if</span> (hrs &gt;= 24) {
						hrs -= 24;
					}
				}
				<span class="comment">//ALLOWED TIME CHECK</span>
				<span class="comment">// This part of code seeks for the first enabled time value for this date.</span>
				<span class="comment">// It is written for the cases when you change day, month or year and the time value is disabled for the new date.</span>
				<span class="comment">// So if you only allow 8:00 - 17:00 on Mondays and you change the date to a Monday but the time is 7:00 it will</span>
				<span class="comment">// automatically move forward to 8:00.</span>

				var new_date = new Date(currentDate);
				<span class="reserved">if</span> (<span class="reserved">this</span>.getDateStatus &amp;&amp; <span class="reserved">this</span>.getDateStatus(currentDate, currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), hrs, mins)) {
					hours = hrs;
					minutes = mins;
					var thresholdDate;
					var now = new Date();
					do {
						<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeInterval) {
							<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeInterval &lt; 60) {
								minutes += <span class="reserved">this</span>.config.timeInterval;
								thresholdDate = new Date(now.getTime() + Date.MINUTE * <span class="reserved">this</span>.config.timeInterval);
							} <span class="reserved">else</span> {
								hrs += <span class="reserved">this</span>.config.timeInterval / 60;
							}
						} <span class="reserved">else</span> {
							minutes += 5;
							thresholdDate = new Date(now.getTime() + Date.MINUTE * 5);
						}
						<span class="reserved">if</span> (dateStartH) {
							<span class="reserved">if</span> (hours &gt; dateStartH) hours = dateStartH;
							<span class="reserved">if</span> (minutes &gt; dateStartM) minutes = dateStartM + 1;
						}

						<span class="reserved">if</span> (minutes &gt;= 60) {
							minutes -= 60;
							hours += 1;
						}
						<span class="reserved">if</span> (hours &gt;= 24) {
							hours -= 24;
						}

						new_date.setMinutes(minutes);
						new_date.setHours(hours);
						<span class="reserved">if</span> (thresholdDate.getDate() != now.getDate() || !<span class="reserved">this</span>.getDateStatus(new_date, currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), hours, minutes)) {
							hrs = hours;
							mins = minutes;
						}
					} <span class="reserved">while</span> ((hrs != hours) || (mins != minutes));
				}

				<span class="comment">//END OF ALLOWED TIME CHECK</span>
				<span class="reserved">if</span> (dateStartH) {
					var tmpDate = new Date(new_date);
					tmpDate.setHours(hrs);
					tmpDate.setMinutes(mins);
					<span class="reserved">if</span> (hrs &lt; dateStartH) hrs = dateStartH;
					<span class="reserved">if</span> (mins &lt; dateStartM &amp;&amp; tmpDate &lt; <span class="reserved">this</span>.currentDate) mins = dateStartM;
				}
				currentDate.setMinutes(mins);
				currentDate.setHours(hrs);
				var pm = (hrs &gt;= 12);
				<span class="reserved">if</span> (pm &amp;&amp; t12 &amp;&amp; hrs != 12) hrs -= 12;
				<span class="reserved">if</span> (!pm &amp;&amp; t12 &amp;&amp; hrs == 0) hrs = 12;
				thisH.firstChild.data = (hrs &lt; 10) ? (<span class="literal">"0"</span> + hrs) : hrs;
				thisM.firstChild.data = (mins &lt; 10) ? (<span class="literal">"0"</span> + mins) : mins;
				<span class="reserved">if</span> (<span class="reserved">this</span>.config.showsTime == <span class="literal">"seconds"</span>) {
					thisS.firstChild.data = (secs &lt; 10) ? (<span class="literal">"0"</span> + secs) : secs;
				}
				<span class="reserved">if</span> (t12)
					thisAP.firstChild.data = pm ? Zapatec.Calendar.i18n(<span class="literal">"pm"</span>, <span class="literal">"ampm"</span>, <span class="reserved">this</span>) : Zapatec.Calendar.i18n(<span class="literal">"am"</span>, <span class="literal">"ampm"</span>, <span class="reserved">this</span>);
			};

			cal.onUpdateTime = <span class="reserved">function</span>(currentDate) {
				var date = dateStart = null;
				var thisH = H;
				var thisM = M;
				var thisS = S;
				var thisAP = AP;
				<span class="reserved">if</span> (!currentDate)
					date = <span class="reserved">this</span>.currentDate;
				<span class="reserved">else</span> {
					date = currentDate;
					dateStart = <span class="reserved">this</span>.currentDate;
					thisH = H1;
					thisM = M1;
					thisS = S1;
					thisAP = AP1;
				}
				var h = parseInt(thisH.firstChild.data, 10);
				<span class="reserved">if</span> (t12) {
					<span class="reserved">if</span> (/pm/i.test(thisAP.firstChild.data) &amp;&amp; h &lt; 12)
						h += 12;
					<span class="reserved">else</span> <span class="reserved">if</span> (/am/i.test(thisAP.firstChild.data) &amp;&amp; h == 12)
						h = 0;
				}
				var d = date.getDate();
				var m = date.getMonth();
				var y = date.getFullYear();
				date.setHours(h);
				<span class="reserved">if</span> (dateStart) {
					<span class="reserved">if</span> (date.setMinutes(parseInt(thisM.firstChild.data, 10)) &lt; dateStart)
						date.setMinutes(dateStart.getMinutes());
				}
				<span class="reserved">else</span>
					date.setMinutes(parseInt(thisM.firstChild.data, 10));
				<span class="reserved">if</span> (<span class="reserved">this</span>.config.showsTime == <span class="literal">"seconds"</span>) {
					date.setSeconds(parseInt(thisS.firstChild.data, 10));
				}
				Zapatec.Date.setFullYear(date, y);
				date.setMonth(m);
				date.setDate(d);
				<span class="reserved">this</span>.dateClicked = false;
				<span class="reserved">this</span>.callHandler();
				<span class="reserved">if</span> (!currentDate)
					<span class="reserved">this</span>.onSetTime(<span class="reserved">this</span>.currentDateEnd);
			};
		})();

		<span class="comment">//empty area after the time controls</span>
		<span class="reserved">if</span> (<span class="reserved">this</span>.config.monthsInRow != 1) {
			<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeRange) row = firstrow;
			cell = Zapatec.Utils.createElement(<span class="literal">"td"</span>, row);
			cell.colSpan = ((<span class="reserved">this</span>.config.weekNumbers) ? 8 : 7) * (<span class="reserved">this</span>.config.monthsInRow - 1) - Math.ceil(emptyColspan);
			<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeRange) cell.rowSpan = 2;
			cell.className = <span class="literal">"timetext"</span>;
			cell.innerHTML = <span class="literal">"&amp;nbsp"</span>;
		}
	} <span class="reserved">else</span> {
		<span class="reserved">this</span>.onSetTime = <span class="reserved">this</span>.onUpdateTime = <span class="reserved">function</span>() {
		};
	}

	<span class="comment">// Status bar</span>
	<span class="reserved">if</span> (!<span class="reserved">this</span>.config.noStatus) {
		row = Zapatec.Utils.createElement(<span class="literal">"tr"</span>, tfoot);
		row.className = <span class="literal">"footrow"</span>;

		cell = hh(Zapatec.Calendar.i18n(<span class="literal">"SEL_DATE"</span>, null, <span class="reserved">this</span>), <span class="reserved">this</span>.config.weekNumbers ? (8 * <span class="reserved">this</span>.config.numberMonths) : (7 * <span class="reserved">this</span>.config.numberMonths), 300);
		cell.className = <span class="literal">"ttip"</span>;
		cell.id = <span class="literal">"zpCal"</span> + <span class="reserved">this</span>.id + <span class="literal">"Status"</span>;
		<span class="reserved">if</span> (<span class="reserved">this</span>.isPopup &amp;&amp; !<span class="reserved">this</span>.config.disableDrag) {
			cell.ttip = Zapatec.Calendar.i18n(<span class="literal">"DRAG_TO_MOVE"</span>, null, <span class="reserved">this</span>);
			cell.style.cursor = <span class="literal">"move"</span>;
		}
		<span class="reserved">this</span>.tooltips = cell;
	}

	div = <span class="reserved">this</span>.monthsCombo = Zapatec.Utils.createElement(<span class="literal">"div"</span>, <span class="reserved">this</span>.element);
	div.className = <span class="literal">"combo"</span>;
	div.id = <span class="literal">"zpCal"</span> + <span class="reserved">this</span>.id + <span class="literal">"MonthDropdownCombo"</span>;
	<span class="reserved">for</span> (i = 0; i &lt; 12; ++i) {
		var mn = Zapatec.Utils.createElement(<span class="literal">"div"</span>);
		mn.className = Zapatec.is_ie ? <span class="literal">"label-IEfix"</span> : <span class="literal">"label"</span>;
		mn.id = <span class="literal">"zpCal"</span> + <span class="reserved">this</span>.id + <span class="literal">"MonthDropdownItem"</span> + i;
		mn.month = i;
		mn.appendChild(window.document.createTextNode(Zapatec.Calendar.i18n(i, <span class="literal">"smn"</span>, <span class="reserved">this</span>)));
		div.appendChild(mn);
	}

	div = <span class="reserved">this</span>.yearsCombo = Zapatec.Utils.createElement(<span class="literal">"div"</span>, <span class="reserved">this</span>.element);
	div.className = <span class="literal">"combo"</span>;
	div.id = <span class="literal">"zpCal"</span> + <span class="reserved">this</span>.id + <span class="literal">"YearDropdownCombo"</span>;
	<span class="reserved">for</span> (i = 0; i &lt; 12; ++i) {
		var yr = Zapatec.Utils.createElement(<span class="literal">"div"</span>);
		yr.className = Zapatec.is_ie ? <span class="literal">"label-IEfix"</span> : <span class="literal">"label"</span>;
		yr.id = <span class="literal">"zpCal"</span> + <span class="reserved">this</span>.id + <span class="literal">"YearDropdownItem"</span> + i;
		yr.appendChild(window.document.createTextNode(<span class="literal">"&amp;nbsp;"</span>));
		div.appendChild(yr);
	}

	div = Zapatec.Utils.createElement(<span class="literal">"div"</span>, <span class="reserved">this</span>.element);
	div.id = <span class="literal">"zpCal"</span> + cal.id + <span class="literal">"HistoryDropdownCombo"</span>;
	div.className = <span class="literal">"combo history"</span>;
	<span class="reserved">this</span>.histCombo = div;

	<span class="comment">// Set this.element to container = first div = upper div</span>
	<span class="reserved">this</span>.element = <span class="reserved">this</span>.container;

	<span class="reserved">this</span>._init(<span class="reserved">this</span>.config.firstDay, <span class="reserved">this</span>.config.date);

	parent.appendChild(<span class="reserved">this</span>.element);
	<span class="reserved">this</span>.isCreate = true;

	<span class="reserved">if</span> (typeof <span class="reserved">this</span>.config.onCreate == <span class="literal">'function'</span>)
		<span class="reserved">this</span>.config.onCreate(<span class="reserved">this</span>);
};

<span class="comment">/**
 * This function handles keypress events that occur while a popup calendar is
 * displayed.  The implementation is quite complicated; this function calls
 * cellClick in order to set the new date as if it was clicked.
 *
 * <span class="attrib">@param</span> ev [Event] the event object
 * <span class="attrib">@return</span> false
 */</span>
Zapatec.Calendar._keyEvent = <span class="reserved">function</span>(ev) {
	var cal = Zapatec.Calendar.activeCalendar;

	<span class="reserved">if</span> (!cal) {
		<span class="reserved">return</span> false;
	}

	<span class="reserved">if</span> (Zapatec.is_ie) {
		ev = window.event;
	}

	var act = (Zapatec.is_ie || ev.type == <span class="literal">"keypress"</span>);
	var K = ev.keyCode;
	var date = new Date(cal.currentDate);
	<span class="reserved">if</span> (ev.ctrlKey) {
		switch (K) {
			case 37: <span class="comment">// KEY left</span>
				act &amp;&amp; Zapatec.Calendar.cellClick(cal._nav_pm);
				break;
			case 38: <span class="comment">// KEY up</span>
				act &amp;&amp; Zapatec.Calendar.cellClick(cal._nav_py);
				break;
			case 39: <span class="comment">// KEY right</span>
				act &amp;&amp; Zapatec.Calendar.cellClick(cal._nav_nm);
				break;
			case 40: <span class="comment">// KEY down</span>
				act &amp;&amp; Zapatec.Calendar.cellClick(cal._nav_ny);
				break;
			default:
				<span class="reserved">return</span> false;
		}
	} <span class="reserved">else</span> switch (K) {
		case 32: <span class="comment">// KEY space (now)</span>
			Zapatec.Calendar.cellClick(cal._nav_now);
			break;
		case 27: <span class="comment">// KEY esc</span>
			act &amp;&amp; cal.callCloseHandler();
			break;
		<span class="comment">//Fix for the key navigation</span>
		case 37: <span class="comment">// KEY left</span>
			<span class="reserved">if</span> (act &amp;&amp; !cal.multiple) {
				date.setTime(date.getTime() - 86400000);
				cal.setDate(date);
			}
			break;
		case 38: <span class="comment">// KEY up</span>
			<span class="reserved">if</span> (act &amp;&amp; !cal.multiple) {
				date.setTime(date.getTime() - 7 * 86400000);
				cal.setDate(date);
			}
			break;
		case 39: <span class="comment">// KEY right</span>
			<span class="reserved">if</span> (act &amp;&amp; !cal.multiple) {
				date.setTime(date.getTime() + 86400000);
				cal.setDate(date);
			}
			break;
		case 40: <span class="comment">// KEY down</span>
			<span class="reserved">if</span> (act &amp;&amp; !cal.multiple) {
				date.setTime(date.getTime() + 7 * 86400000);
				cal.setDate(date);
			}
			break;
		case 13: <span class="comment">// KEY enter</span>
			<span class="reserved">if</span> (act) {
				<span class="comment">//FIX for Enter key!</span>
				Zapatec.Calendar.cellClick(cal.currentDateEl);
			}
			break;
		default:
		<span class="comment">// Close the calendar.</span>
			Zapatec.Calendar._checkCalendar;
			<span class="reserved">return</span> false;
	}
	<span class="reserved">return</span> Zapatec.Utils.stopEvent(ev);
};

<span class="comment">/**
 * (RE)Initializes the calendar to the given date and firstDay.
 *
 * This function perform the action of actually displaying the day names and
 * dates in the calendar.  But first, it checks if the passed date fits in the
 * allowed range, configured by the "minYear", "maxYear", "minMonth" and
 * "maxMonth" properties of the Calendar object.
 *
 * It takes care to highlight special days (calling the
 * calendar.getDateStatus() function which can be overridden by external
 * scripts) or to highlight any dates that might be selected (for instance when
 * multiple dates is on, this function will call _initMultipleDates() to
 * highlight selected dates accordingly).
 *
 * This function is highly optimized for speed, therefore the code in it is not
 * trivial and what it does might not seem obvious. :-) So, WARNING, this is
 * voodoo.  If you want to properly understand the code you should analyze it
 * line by line and try to execute it step by step; use the Venkman JS
 * debugger.
 *
 * <span class="attrib">@param</span> firstDay [int] the first day of week, 0 for Sunday, 1 for Monday, etc.
 * <span class="attrib">@param</span> date [Date] the date to initialize the calendar to
 *
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>._init = <span class="reserved">function</span> (firstDay, date, last) {
	var today = new Date();
	var TD = today.getDate();
	var TY = today.getFullYear();
	var TM = today.getMonth();
	var status, toolTip, k, tmpDate;
	<span class="comment">//this.table.style.visibility = "hidden";</span>

	<span class="reserved">if</span> (<span class="reserved">this</span>.getDateStatus &amp;&amp; !last) {
		status = <span class="reserved">this</span>.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate());
		var backupDate = new Date(date);
		<span class="reserved">while</span> (((status == true) || (status == <span class="literal">"disabled"</span>)) &amp;&amp; (backupDate.getMonth() == date.getMonth())) {
			date.setTime(date.getTime() + 86400000);
			status = <span class="reserved">this</span>.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate());
		}
		<span class="reserved">if</span> (backupDate.getMonth() != date.getMonth()) {
			date = new Date(backupDate);
			<span class="reserved">while</span> (((status == true) || (status == <span class="literal">"disabled"</span>)) &amp;&amp; (backupDate.getMonth() == date.getMonth())) {
				date.setTime(date.getTime() - 86400000);
				status = <span class="reserved">this</span>.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate());
			}
		}
		<span class="reserved">if</span> (backupDate.getMonth() != date.getMonth()) {
			last = true;
			date = new Date(backupDate);
		}
	}
	var year = date.getFullYear();
	var month = date.getMonth();
	var rowsOfMonths = Math.floor(<span class="reserved">this</span>.config.numberMonths / <span class="reserved">this</span>.config.monthsInRow);
	var minMonth;
	var diffMonth, last_row, before_control;
	<span class="reserved">if</span> (!<span class="reserved">this</span>.config.vertical) {
		diffMonth = (<span class="reserved">this</span>.config.controlMonth - 1);
		minMonth = month - diffMonth;
	} <span class="reserved">else</span> {
		last_row = ((<span class="reserved">this</span>.config.numberMonths - 1) % <span class="reserved">this</span>.config.monthsInRow) + 1;
		before_control = (<span class="reserved">this</span>.config.controlMonth - 1) % <span class="reserved">this</span>.config.monthsInRow;
		bottom = (before_control &gt;= (last_row) ? (last_row) : (before_control));
		diffMonth = (before_control) * (rowsOfMonths - 1) + Math.floor((<span class="reserved">this</span>.config.controlMonth - 1) / <span class="reserved">this</span>.config.monthsInRow) + bottom;
		minMonth = month - diffMonth;
	}
	var minYear = year;
	<span class="reserved">if</span> (minMonth &lt; 0) {
		minMonth += 12;
		--minYear;
	}
	var maxMonth = minMonth + <span class="reserved">this</span>.config.numberMonths - 1;
	var maxYear = minYear;
	<span class="reserved">if</span> (maxMonth &gt; 11) {
		maxMonth -= 12;
		++maxYear;
	}
	<span class="reserved">function</span> disableControl(ctrl) {
		Zapatec.Calendar._del_evs(ctrl);
		ctrl.disabled = true;
		ctrl.className = <span class="literal">"button"</span>;
		ctrl.innerHTML = <span class="literal">"&lt;div&gt;&amp;nbsp&lt;/div&gt;"</span>;
	}
	<span class="reserved">function</span> enableControl(ctrl, sign) {
		Zapatec.Calendar._add_evs(ctrl);
		ctrl.disabled = false;
		ctrl.className = <span class="literal">"button nav"</span>;
		ctrl.innerHTML = sign;
	}

	<span class="reserved">if</span> ((minYear &lt;= <span class="reserved">this</span>.minYear) || <span class="reserved">this</span>.config.disableYearNav) {
		<span class="reserved">if</span> (!<span class="reserved">this</span>._nav_py.disabled) {
			disableControl(<span class="reserved">this</span>._nav_py);
		}
	} <span class="reserved">else</span> {
		<span class="reserved">if</span> (<span class="reserved">this</span>._nav_py.disabled) {
			enableControl(<span class="reserved">this</span>._nav_py, <span class="literal">"&amp;#x00ab;"</span>);
		}
	}

	<span class="reserved">if</span> (maxYear &gt;= <span class="reserved">this</span>.maxYear || <span class="reserved">this</span>.config.disableYearNav) {
		<span class="reserved">if</span> (!<span class="reserved">this</span>._nav_ny.disabled) {
			disableControl(<span class="reserved">this</span>._nav_ny);
		}
	} <span class="reserved">else</span> {
		<span class="reserved">if</span> (<span class="reserved">this</span>._nav_ny.disabled) {
			enableControl(<span class="reserved">this</span>._nav_ny, <span class="literal">"&amp;#x00bb;"</span>);
		}
	}

	<span class="reserved">if</span> (((minYear == <span class="reserved">this</span>.minYear) &amp;&amp; (minMonth &lt;= <span class="reserved">this</span>.minMonth)) || (minYear &lt; <span class="reserved">this</span>.minYear)) {
		<span class="reserved">if</span> (!<span class="reserved">this</span>._nav_pm.disabled) {
			disableControl(<span class="reserved">this</span>._nav_pm);
		}
	} <span class="reserved">else</span> {
		<span class="reserved">if</span> (<span class="reserved">this</span>._nav_pm.disabled) {
			enableControl(<span class="reserved">this</span>._nav_pm, <span class="literal">"&amp;#x2039;"</span>);
		}
	}
	<span class="reserved">if</span> (((maxYear == <span class="reserved">this</span>.maxYear) &amp;&amp; (maxMonth &gt;= <span class="reserved">this</span>.maxMonth)) || (maxYear &gt; <span class="reserved">this</span>.maxYear)) {
		<span class="reserved">if</span> (!<span class="reserved">this</span>._nav_nm.disabled) {
			disableControl(<span class="reserved">this</span>._nav_nm);
		}
	} <span class="reserved">else</span> {
		<span class="reserved">if</span> (<span class="reserved">this</span>._nav_nm.disabled) {
			enableControl(<span class="reserved">this</span>._nav_nm, <span class="literal">"&amp;#x203a;"</span>);
		}
	}

	<span class="comment">//FIX for range checking : spreading of the range on 1 month on the both sides;</span>
	upperMonth = <span class="reserved">this</span>.maxMonth + 1;
	upperYear = <span class="reserved">this</span>.maxYear;
	<span class="reserved">if</span> (upperMonth &gt; 11) {
		upperMonth -= 12;
		++upperYear;
	}
	bottomMonth = <span class="reserved">this</span>.minMonth - 1;
	bottomYear = <span class="reserved">this</span>.minYear;
	<span class="reserved">if</span> (bottomMonth &lt; 0) {
		bottomMonth += 12;
		--bottomYear;
	}
	maxDate1 = new Date(maxYear, maxMonth, Zapatec.Date.getMonthDays(date, maxMonth), 23, 59, 59, 999);
	maxDate2 = new Date(upperYear, upperMonth, 1, 0, 0, 0, 0);
	minDate1 = new Date(minYear, minMonth, 1, 0, 0, 0, 0);
	minDate2 = new Date(bottomYear, bottomMonth, Zapatec.Date.getMonthDays(date, bottomMonth), 23, 59, 59, 999);
	var today = new Date();

	<span class="reserved">if</span> (maxDate1.getTime() &gt; maxDate2.getTime()) {
		<span class="reserved">if</span> (today &lt; maxDate2.getTime())
			date.setTime(today.getTime());
		<span class="reserved">else</span>
			date.setTime(date.getTime() - (maxDate1.getTime() - maxDate2.getTime()) - 4);
	}
	<span class="reserved">if</span> (minDate1.getTime() &lt; minDate2.getTime()) {
		<span class="reserved">if</span> (today &gt; minDate2.getTime())
			date.setTime(today.getTime());
		<span class="reserved">else</span>
			date.setTime(date.getTime() + (minDate2.getTime() - minDate1.getTime()) + 4);
	}
	delete maxDate1;
	delete maxDate2;
	delete minDate1;
	delete minDate2;
	<span class="reserved">this</span>.config.firstDay = firstDay;
	<span class="reserved">if</span> (!last) {
		<span class="reserved">this</span>.currentDate = date;
		<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeRange &amp;&amp; !<span class="reserved">this</span>.currentDateEnd) <span class="reserved">this</span>.currentDateEnd = new Date(date);
	}
	<span class="reserved">this</span>.config.date = date;
	Zapatec.Date.setDateOnly((<span class="reserved">this</span>.config.date = new Date(<span class="reserved">this</span>.config.date)), date);
	year = <span class="reserved">this</span>.config.date.getFullYear();
	month = <span class="reserved">this</span>.config.date.getMonth();
	var initMonth = date.getMonth();
	var mday = <span class="reserved">this</span>.config.date.getDate();
	var no_days = Zapatec.Date.getMonthDays(date);

	<span class="comment">// Get first displayed date</span>
	var months = new Array();
	var validMonths = new Array();
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.numberMonths % <span class="reserved">this</span>.config.monthsInRow &gt; 0) {
		++rowsOfMonths;
	}
	<span class="comment">//creating of the array of date objects for every month</span>
	var validMonth, day1, hrs;
	<span class="reserved">for</span> (var l = 1; l &lt;= rowsOfMonths; ++l) {
		months[l] = new Array();
		validMonths[l] = new Array();
		<span class="reserved">for</span> (k = 1; (k &lt;= <span class="reserved">this</span>.config.monthsInRow) &amp;&amp; ((l - 1) * <span class="reserved">this</span>.config.monthsInRow + k &lt;= <span class="reserved">this</span>.config.numberMonths); ++k) {
			tmpDate = new Date(date);
			<span class="reserved">if</span> (<span class="reserved">this</span>.config.vertical) {
				validMonth = date.getMonth() - diffMonth + ((k - 1) * (rowsOfMonths - 1) + (l - 1) + ((last_row &lt; k) ? (last_row) : (k - 1)));
			} <span class="reserved">else</span> {
				validMonth = date.getMonth() - diffMonth + (l - 1) * <span class="reserved">this</span>.config.monthsInRow + k - 1;
			}
			<span class="reserved">if</span> (validMonth &lt; 0) {
				zapatecDate.setFullYear(tmpDate, tmpDate.getFullYear() - 1);
				validMonth = validMonth + 12;
			}
			<span class="reserved">if</span> (validMonth &gt; 11) {
				zapatecDate.setFullYear(tmpDate, tmpDate.getFullYear() + 1);
				validMonth = validMonth - 12;
			}
			validMonths[l][k] = validMonth;
			tmpDate.setDate(1);
			tmpDate.setMonth(validMonth);
			day1 = (tmpDate.getDay() - <span class="reserved">this</span>.config.firstDay) % 7;
			<span class="reserved">if</span> (day1 &lt; 0) {
				day1 += 7;
			}
			hrs = tmpDate.getHours();
			tmpDate.setDate(-day1);
			tmpDate.setDate(tmpDate.getDate() + 1);
			<span class="reserved">if</span> (hrs != tmpDate.getHours()) {
				tmpDate.setDate(1);
				tmpDate.setMonth(validMonth);
				tmpDate.setDate(-day1);
				tmpDate.setDate(tmpDate.getDate() + 1);
			}
			months[l][k] = tmpDate;
		}
	}
	<span class="comment">// Range of displayed dates</span>
	<span class="comment">// Start date</span>
	var oRange = <span class="reserved">this</span>.calRange = {
		from: new Date(months[1][1])
	};
	<span class="comment">//every iteration of the cycle fills one row of months with values;</span>
	var MN = Zapatec.Calendar.i18n(month, <span class="literal">"smn"</span>, <span class="reserved">this</span>);
	var weekend = Zapatec.Calendar.i18n(<span class="literal">"WEEKEND"</span>, null, <span class="reserved">this</span>);
	var dates = <span class="reserved">this</span>.config.multiple ? (<span class="reserved">this</span>.datesCells = {}) : null;
	var DATETXT = <span class="reserved">this</span>.config.dateText;
	var row, i, k, cell, hasdays, iday, wday, dmonth, dyear, current_month;
	<span class="reserved">for</span> (var l = 1; l &lt;= rowsOfMonths; ++l) {
		row = <span class="reserved">this</span>.tbody[l].firstChild;
		<span class="reserved">for</span> (i = 7; --i &gt; 0; row = row.nextSibling) {
			cell = row.firstChild;
			hasdays = false;
			<span class="comment">//this fills one row of days for all the months in the row</span>
			<span class="reserved">for</span> (k = 1; (k &lt;= <span class="reserved">this</span>.config.monthsInRow) &amp;&amp; ((l - 1) * <span class="reserved">this</span>.config.monthsInRow + k &lt;= <span class="reserved">this</span>.config.numberMonths); ++k) {
				date = months[l][k];
				<span class="reserved">if</span> (<span class="reserved">this</span>.config.weekNumbers) {
					cell.className = <span class="literal">"day wn"</span>;
					cell.innerHTML = zapatecDate.getWeekNumber(date);
					<span class="reserved">if</span> (k &gt; 1) {
						cell.className += <span class="literal">" month-left-border"</span>;
					}
					cell = cell.nextSibling;
				}
				row.className = <span class="literal">"daysrow"</span>;
				row.id = <span class="literal">"zpCal"</span> + <span class="reserved">this</span>.id + <span class="literal">"Daysrow"</span> + (6 - i);
				<span class="reserved">if</span> (<span class="reserved">this</span>.config.hideNavPanel) {
					hasdays = false;
				}
				<span class="reserved">for</span> (j = 7; cell &amp;&amp; (iday = date.getDate()) &amp;&amp; (j &gt; 0); date.setDate(iday + 1),((date.getDate() == iday) ? (date.setHours(1) &amp;&amp; date.setDate(iday + 1)) : (false)),cell = cell.nextSibling,--j) {
					wday = date.getDay();
					dmonth = date.getMonth();
					dyear = date.getFullYear();
					cell.className = <span class="literal">"day"</span>;
					<span class="reserved">if</span> ((!<span class="reserved">this</span>.config.weekNumbers) &amp;&amp; (j == 7) &amp;&amp; (k != 1)) {
						cell.className += <span class="literal">" month-left-border"</span>;
					}
					<span class="reserved">if</span> ((j == 1) &amp;&amp; (k != <span class="reserved">this</span>.config.monthsInRow)) {
						cell.className += <span class="literal">" month-right-border"</span>;
					}
					current_month = !(cell.otherMonth = !(dmonth == validMonths[l][k]));
					<span class="reserved">if</span> (!current_month) {
						<span class="reserved">if</span> (<span class="reserved">this</span>.config.showOthers) {
							cell.className += <span class="literal">" othermonth"</span>;
						} <span class="reserved">else</span> {
							cell.className += <span class="literal">" true"</span>;
							cell.innerHTML = <span class="literal">"&amp;nbsp;"</span>;
							continue;
						}
					} <span class="reserved">else</span> {
						hasdays = true;
					}
					cell.innerHTML = DATETXT ? DATETXT(date, dyear, dmonth, iday) : iday;
					dates &amp;&amp; (dates[zapatecDate.print.call(<span class="reserved">this</span>, date, <span class="literal">"%Y%m%d"</span>)] = cell);
					<span class="reserved">if</span> (!cell.disabled) {
						cell.caldate = [dyear, dmonth, iday];
						cell.ttip = <span class="literal">"_"</span>;
						<span class="reserved">if</span> ((weekend != null) &amp;&amp; (weekend.indexOf(wday.toString()) != -1)) {
							cell.className += cell.otherMonth ? <span class="literal">" oweekend"</span> : <span class="literal">" weekend"</span>;
						}
						<span class="reserved">if</span> (dyear == TY &amp;&amp; dmonth == TM &amp;&amp; iday == TD) {
							cell.className += <span class="literal">" today"</span>;
							<span class="reserved">if</span> (!current_month &amp;&amp; <span class="reserved">this</span>.config.showOthers) {
								cell.className += <span class="literal">" othermonthtoday"</span>;
							}
							cell.ttip += Zapatec.Calendar.i18n(<span class="literal">"PART_TODAY"</span>, null, <span class="reserved">this</span>);
						}
						<span class="reserved">if</span> (
							!<span class="reserved">this</span>.config.multiple &amp;&amp; current_month &amp;&amp;
							iday == <span class="reserved">this</span>.currentDate.getDate() &amp;&amp; <span class="reserved">this</span>.hiliteToday &amp;&amp;
							(dmonth == <span class="reserved">this</span>.currentDate.getMonth()) &amp;&amp;
							(dyear == <span class="reserved">this</span>.currentDate.getFullYear())
							) {
							cell.className += <span class="literal">" selected"</span>;
							row.className += <span class="literal">" rowhilite"</span>;
							<span class="reserved">this</span>.lastRowHilite = row;
							<span class="reserved">this</span>.currentDateEl = cell;
						}
					}
					<span class="reserved">if</span> (<span class="reserved">this</span>.getDateStatus) {
						status = <span class="reserved">this</span>.getDateStatus(date, dyear, dmonth, iday);
						<span class="reserved">if</span> (<span class="reserved">this</span>.getDateToolTip) {
							toolTip = <span class="reserved">this</span>.getDateToolTip(date, dyear, dmonth, iday);
							<span class="reserved">if</span> (toolTip) {
								cell.title = toolTip;
							}
						}
						<span class="reserved">if</span> (status == true) {
							cell.className += <span class="literal">" disabled"</span>;
						} <span class="reserved">else</span> {
							cell.className += <span class="literal">" "</span> + status;
						}
					}
				}
				<span class="reserved">if</span> (!(hasdays || !<span class="reserved">this</span>.config.hideNavPanel &amp;&amp; <span class="reserved">this</span>.config.showOthers)) {
					row.className = <span class="literal">"emptyrow"</span>;
				}
			}
			<span class="reserved">if</span> ((i == 1) &amp;&amp; (l &lt; rowsOfMonths)) {
				<span class="reserved">if</span> (row.className == <span class="literal">"emptyrow"</span>) {
					row = row.previousSibling;
				}
				cell = row.firstChild;
				<span class="reserved">while</span> (cell != null) {
					cell.className += <span class="literal">" month-bottom-border"</span>;
					cell = cell.nextSibling;
				}
			}
		}
	}
	<span class="comment">// End date</span>
	oRange.to = new Date(date.setDate(date.getDate() - 1));

	<span class="comment">//filling of all titles for the months</span>
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.numberMonths == 1) {
		<span class="reserved">this</span>.title.innerHTML = Zapatec.Calendar.i18n(month, <span class="literal">"mn"</span>, <span class="reserved">this</span>) + <span class="literal">" "</span> + year;
		<span class="reserved">if</span> (<span class="reserved">this</span>.config &amp;&amp; <span class="reserved">this</span>.config.titleHtml)
			<span class="reserved">if</span> (typeof <span class="reserved">this</span>.config.titleHtml == <span class="literal">'function'</span>)
				<span class="reserved">this</span>.title.innerHTML = <span class="reserved">this</span>.config.titleHtml(<span class="reserved">this</span>.title.innerHTML, month, year)
			<span class="reserved">else</span>
				<span class="reserved">this</span>.title.innerHTML += <span class="reserved">this</span>.config.titleHtml
	} <span class="reserved">else</span> {

		<span class="reserved">if</span> (<span class="reserved">this</span>.config &amp;&amp; <span class="reserved">this</span>.config.titleHtml)
			<span class="reserved">if</span> (typeof <span class="reserved">this</span>.config.titleHtml == <span class="literal">'function'</span>)
				<span class="reserved">this</span>.title.innerHTML = <span class="reserved">this</span>.config.titleHtml(Zapatec.Calendar.i18n(month, <span class="literal">"mn"</span>, <span class="reserved">this</span>) + <span class="literal">", "</span> + year, month, year)
			<span class="reserved">else</span>
				<span class="reserved">this</span>.title.innerHTML = <span class="reserved">this</span>.config.titleHtml

		<span class="reserved">for</span> (var l = 1; l &lt;= rowsOfMonths; ++l) {
			<span class="reserved">for</span> (k = 1; (k &lt;= <span class="reserved">this</span>.config.monthsInRow) &amp;&amp; ((l - 1) * <span class="reserved">this</span>.config.monthsInRow + k &lt;= <span class="reserved">this</span>.config.numberMonths); ++k) {
				<span class="reserved">if</span> (<span class="reserved">this</span>.config.vertical) {
					validMonth = month - diffMonth + ((k - 1) * (rowsOfMonths - 1) + (l - 1) + ((last_row &lt; k) ? (last_row) : (k - 1)));
				} <span class="reserved">else</span> {
					validMonth = month - diffMonth + (l - 1) * <span class="reserved">this</span>.config.monthsInRow + k - 1;
				}
				validYear = year;
				<span class="reserved">if</span> (validMonth &lt; 0) {
					--validYear;
					validMonth = 12 + validMonth;
				}
				<span class="reserved">if</span> (validMonth &gt; 11) {
					++validYear;
					validMonth = validMonth - 12;
				}
				<span class="reserved">this</span>.titles[l][k].onclick = new Function(
					<span class="literal">'zapatecWidgetCallMethod('</span> + <span class="reserved">this</span>.id +
					<span class="literal">',"fireEvent","calMonthClicked",{fullYear:"'</span> + validYear +
					<span class="literal">'",month:"'</span> + validMonths[l][k] + <span class="literal">'"})'</span>
					);
				<span class="reserved">this</span>.titles[l][k].innerHTML = Zapatec.Calendar.i18n(validMonths[l][k], <span class="literal">"mn"</span>, <span class="reserved">this</span>) + <span class="literal">" "</span> + validYear;
			}
		}
	}

	<span class="reserved">this</span>.onSetTime();
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeRange)
		<span class="reserved">this</span>.onSetTime(<span class="reserved">this</span>.currentDateEnd);
	<span class="comment">//this.table.style.visibility = "visible";</span>
	<span class="reserved">this</span>._initMultipleDates();
	<span class="reserved">this</span>.updateWCH();
	<span class="comment">// PROFILE</span>
	<span class="comment">// this.showHint("Generated in " + ((new Date()) - today) + " ms");</span>
};

<span class="comment">/**
 * Returns range of displayed dates.
 *
 * &lt;pre&gt;
 * Returns object:
 * {
 *   from: [object] first displayed Date,
 *   to: [object] last displayed Date
 * }
 * &lt;/pre&gt;
 *
 * <span class="attrib">@return</span> Range of dates
 * <span class="attrib">@type</span> object
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.getRange = <span class="reserved">function</span>() {
	<span class="comment">// Range is formed in _init</span>
	<span class="reserved">return</span> <span class="reserved">this</span>.calRange;
};

<span class="comment">/**
 * Find a range date for date in multiple array
 * <span class="attrib">@private</span>
 * <span class="attrib">@param</span> {Object} date
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>._findDateFormMultiple = <span class="reserved">function</span> (date, multipleRange) {
	var d = null;
	<span class="reserved">for</span> (var i in multipleRange) {
		d = multipleRange[i];
		<span class="reserved">if</span> (date.substr(0, 8) == zapatecDate.print.call(<span class="reserved">this</span>, d, <span class="literal">"%Y%m%d"</span>)) {
			<span class="reserved">this</span>.config.multipleRange[date] = multipleRange[i];
			<span class="reserved">return</span> <span class="reserved">this</span>.config.multipleRange[date];
		}
	}

	<span class="comment">// If pair was not found set end date to start date</span>
	<span class="reserved">this</span>.config.multipleRange[date] = date;
	<span class="reserved">return</span>;
}

<span class="comment">/**
 * If "multiple dates" is selected (the calendar.multiple property) this
 * function will highlight cells that display dates that are selected.  It is
 * only called from the _init() function.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>._initMultipleDates = <span class="reserved">function</span>() {
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.multiple) {
		var d = null;
		var dateEnd = null;
		<span class="reserved">for</span> (var i in <span class="reserved">this</span>.config.multiple) {
			d = <span class="reserved">this</span>.config.multiple[i];
			<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeRange) dateEnd = <span class="reserved">this</span>.config.multiple[i];
			var cell = <span class="reserved">this</span>.datesCells[zapatecDate.print.call(<span class="reserved">this</span>, d, <span class="literal">"%Y%m%d"</span>)];
			<span class="reserved">if</span> (!<span class="reserved">this</span>.config.multiple[zapatecDate.print.call(<span class="reserved">this</span>, d, <span class="literal">"%Y%m%d"</span>)]) {
				<span class="reserved">this</span>.config.multiple[zapatecDate.print.call(<span class="reserved">this</span>, d, <span class="literal">"%Y%m%d"</span>)] = d;
				delete(<span class="reserved">this</span>.config.multiple[i]);
			}
			<span class="reserved">if</span> (!d)
				continue;
			<span class="reserved">if</span> (cell) {
				Zapatec.Utils.addClass(cell, <span class="literal">"selected"</span>);
			}
		}
		<span class="reserved">if</span> (d != null &amp;&amp; <span class="reserved">this</span>.config.showsTime) {
			<span class="reserved">this</span>.currentDate = new Date(d);
			<span class="reserved">this</span>.onSetTime();
			<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeRange) {
				<span class="reserved">this</span>.currentDateEnd = new Date(dateEnd);
				<span class="reserved">this</span>.onSetTime(<span class="reserved">this</span>.currentDateEnd);
			}
		}
	}
};

<span class="comment">/**
 * Given a Date object, this function will "toggle" it in the calendar; that
 * is, it will select it if not already selected, or unselect it if was already
 * selected.  The array of dates is updated accordingly and the cell object
 * will be added or removed the appropriate class name ("selected").  Of
 * course, this only takes place if "multiple dates" is selected.
 *
 * _toggleMultipleDate - for old versions
 *
 * <span class="attrib">@param</span> date [Date] the date to (un)select.
 * <span class="attrib">@param</span> date1 [Date] the multiple pair to date for (un)selection.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>._toggleMultipleDate = Zapatec.Calendar.<span class="reserved">prototype</span>.toggleMultipleDate = <span class="reserved">function</span>(date, date1) {
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.multiple) {
		var ds = zapatecDate.print.call(<span class="reserved">this</span>, date, <span class="literal">"%Y%m%d"</span>);
		var cell = <span class="reserved">this</span>.datesCells[zapatecDate.print.call(<span class="reserved">this</span>, date, <span class="literal">"%Y%m%d"</span>)];
		<span class="reserved">if</span> (cell) {
			var d = <span class="reserved">this</span>.config.multiple[ds];
			<span class="reserved">if</span> (!d) {
				Zapatec.Utils.addClass(cell, <span class="literal">"selected"</span>);
				<span class="reserved">this</span>.config.multiple[ds] = date;
				<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeRange) {
					<span class="reserved">this</span>.config.multipleRange[ds] = (date1 ? date1 : date);
				}
			} <span class="reserved">else</span> {
				Zapatec.Utils.removeClass(cell, <span class="literal">"selected"</span>);
				delete <span class="reserved">this</span>.config.multiple[ds];
				<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeRange) delete <span class="reserved">this</span>.config.multipleRange[ds];
			}
		}
	}
};

<span class="comment">/**
 * This method affects control month. It changes the range of displayed
 * dates so the control month contains the date passed as an argument.
 * For example if we have 3 month Calendar with second month as a control
 * and we call cal.navigateTo(new Date(2007, 10, 11)), the Calendar will show
 * October-November-December (10 is November as numeration starts with zero).
 *
 * <span class="attrib">@public</span>
 *
 * <span class="attrib">@param</span> date [Date] the date to set.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.navigateTo = <span class="reserved">function</span> (date) {
	<span class="reserved">if</span> (<span class="reserved">this</span>.setDate(date, false) &amp;&amp; Zapatec.Calendar.cellClick(<span class="reserved">this</span>.currentDateEl))
		<span class="reserved">return</span> true;
	<span class="reserved">return</span> false;
}

<span class="comment">/**
 * This method returns the date representing the year and month shown in control month.
 * The rest part of the Date object is 1st day and zeros.
 *
 * <span class="attrib">@public</span>
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.getNavigationPos = <span class="reserved">function</span> () {
	<span class="reserved">if</span> (!<span class="reserved">this</span>.currentDate)
		<span class="reserved">return</span> null;
	<span class="reserved">return</span> <span class="reserved">this</span>.currentDate;
}

<span class="comment">/**
 * Moves the Calendar view one month forward.
 *
 * <span class="attrib">@public</span>
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.nextMonth = <span class="reserved">function</span> () {
	<span class="reserved">if</span> (<span class="reserved">this</span>._nav_nm &amp;&amp; Zapatec.Calendar.cellClick(<span class="reserved">this</span>._nav_nm))
		<span class="reserved">return</span> true;

	<span class="reserved">return</span> false;
}

<span class="comment">/**
 * Moves the Calendar view one month backward.
 *
 * <span class="attrib">@public</span>
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.prevMonth = <span class="reserved">function</span> () {
	<span class="reserved">if</span> (<span class="reserved">this</span>._nav_pm &amp;&amp; Zapatec.Calendar.cellClick(<span class="reserved">this</span>._nav_pm))
		<span class="reserved">return</span> true;

	<span class="reserved">return</span> false;
}

<span class="comment">/**
 * Moves the Calendar view one year forward.
 *
 * <span class="attrib">@public</span>
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.nextYear = <span class="reserved">function</span> () {
	<span class="reserved">if</span> (<span class="reserved">this</span>._nav_ny &amp;&amp; Zapatec.Calendar.cellClick(<span class="reserved">this</span>._nav_ny))
		<span class="reserved">return</span> true;

	<span class="reserved">return</span> false;
}

<span class="comment">/**
 * Moves the Calendar view one year backward.
 *
 * <span class="attrib">@public</span>
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.prevYear = <span class="reserved">function</span> () {
	<span class="reserved">if</span> (<span class="reserved">this</span>._nav_py &amp;&amp; Zapatec.Calendar.cellClick(<span class="reserved">this</span>._nav_py))
		<span class="reserved">return</span> true;

	<span class="reserved">return</span> false;
}

<span class="comment">/**
 * Call this in order to install a function handler that returns a tooltip for
 * the given date.  For example:
 *
 * \code
 *	function myHandler(date) {
 *		var str = Zapatec.Date.print(date, "%Y/%m/%d");
 *		if (str == "1979/08/03") {
 *			return "Happy birthday Mishoo! :D";
 *		}
 *		return str;
 *	}
 *	calendar.setDateToolTipHandler(myHandler);
 * \endcode
 *
 * The tooltip handler is a "unary" function (receives one argument).  The
 * argument passed is a date object and the function should return the tooltip
 * for that date.
 *
 * <span class="attrib">@param</span> unaryFunction [function] your tooltip handler, as described above
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.setDateToolTipHandler = <span class="reserved">function</span> (unaryFunction) {
	<span class="reserved">this</span>.getDateToolTip = unaryFunction;
};

<span class="comment">/**
 * Moves the calendar to the specified date.  If \em date is not passed, then
 * the "today" date is assumed.  This function does range checking and displays
 * an error in the status bar if the new date is not allowed by the configured
 * calendar range.  Otherwise, it simply calls _init() with the new date.
 *
 * <span class="attrib">@param</span> date [Date, optional] the date object.
 *
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.setDate = <span class="reserved">function</span> (date, justInit) {
	<span class="comment">// workaround for some bugs in our parseDate code</span>
	<span class="reserved">if</span> (!date)
		date = new Date();
	<span class="reserved">if</span> (!Zapatec.Date.equalsTo(date, <span class="reserved">this</span>.config.date)) {
		var year = date.getFullYear(), m = date.getMonth();
		<span class="reserved">if</span> (year &lt; <span class="reserved">this</span>.minYear || (year == <span class="reserved">this</span>.minYear &amp;&amp; m &lt; <span class="reserved">this</span>.minMonth))
			<span class="reserved">this</span>.showHint(<span class="literal">"&lt;div class='error'&gt;"</span> + Zapatec.Calendar.i18n(<span class="literal">"E_RANGE"</span>, null, <span class="reserved">this</span>) + <span class="literal">" \&gt;\&gt;\&gt;&lt;/div&gt;"</span>);
		<span class="reserved">else</span> <span class="reserved">if</span> (year &gt; <span class="reserved">this</span>.maxYear || (year == <span class="reserved">this</span>.maxYear &amp;&amp; m &gt; <span class="reserved">this</span>.maxMonth))
			<span class="reserved">this</span>.showHint(<span class="literal">"&lt;div class='error'&gt;\&lt;\&lt;\&lt; "</span> + Zapatec.Calendar.i18n(<span class="literal">"E_RANGE"</span>, null, <span class="reserved">this</span>) + <span class="literal">"&lt;/div&gt;"</span>);
		<span class="reserved">else</span> {
			<span class="reserved">this</span>._init(<span class="reserved">this</span>.config.firstDay, date, justInit);
			<span class="reserved">return</span> true;
		}

		<span class="reserved">return</span> false;
	}

	<span class="reserved">return</span> true;
};

<span class="comment">/**
 * Displays a hint in the status bar
 *
 * <span class="attrib">@param</span> text [string] what to display
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.showHint = <span class="reserved">function</span>(text) {
	<span class="reserved">if</span> (!<span class="reserved">this</span>.config.noStatus)
		<span class="reserved">this</span>.tooltips.innerHTML = text;
};

<span class="comment">/**
 * Refreshes the calendar.  Useful if the "disabledHandler" function is
 * dynamic, meaning that the list of disabled date can change at runtime.  Just
 * call this function if you think that the list of disabled dates should
 * change.
 *
 * This function simply calls _init() using the current firstDay and the
 * current calendar date.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.reinit = <span class="reserved">function</span>() {
	<span class="reserved">this</span>._init(<span class="reserved">this</span>.config.firstDay, <span class="reserved">this</span>.config.date);
};

<span class="comment">/**
 * "refresh()" isn't a good name for it: this function _destroys_ the calendar
 * object and creates another one with the same parameters.  This comes in
 * handy for the calendar wizard where we need to reconstruct the calendar for
 * virtually any property change.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.refresh = <span class="reserved">function</span>() {
	var p = <span class="reserved">this</span>.isPopup ? null : <span class="reserved">this</span>.element.parentNode;
	var x = parseInt(<span class="reserved">this</span>.element.style.left);
	var y = parseInt(<span class="reserved">this</span>.element.style.top);
	<span class="reserved">this</span>.destroy();
	<span class="reserved">this</span>.isCreate = false;
	<span class="reserved">this</span>.init(<span class="reserved">this</span>.config);
	<span class="reserved">if</span> (<span class="reserved">this</span>.isPopup) {
		<span class="reserved">this</span>.showAt(x, y);
	}
};

<span class="comment">/**
 * Configures the "firstDay" parameter of the calendar.
 *
 * <span class="attrib">@param</span> firstDay [int] the new first day of week, 0 for Sunday, 1 for Monday, etc.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.setFirstDayOfWeek = <span class="reserved">function</span> (firstDay) {
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.firstDay != firstDay) {
		<span class="reserved">this</span>._init(firstDay, <span class="reserved">this</span>.config.date);
		<span class="comment">//displaying the day names for all the rows of the months</span>
		var rowsOfMonths = Math.floor(<span class="reserved">this</span>.config.numberMonths / <span class="reserved">this</span>.config.monthsInRow);
		<span class="reserved">if</span> (<span class="reserved">this</span>.config.numberMonths % <span class="reserved">this</span>.config.monthsInRow &gt; 0) {
			++rowsOfMonths;
		}
		<span class="reserved">for</span> (var l = 1; l &lt;= rowsOfMonths; ++l) {
			<span class="reserved">this</span>.firstDayName = <span class="reserved">this</span>.rowsOfDayNames[l];
			<span class="reserved">this</span>._displayWeekdays();
		}
	}
};

<span class="comment">/**
 * These functions allow one to install a handler that gets called for each
 * date when a month is displayed in the calendar.  Based on this handler's
 * return value, that date can be disabled or highlighted using a class name
 * returned by the handler.
 *
 * The handler has the following prototype:
 *
 * \code
 *	function dateStatus(date, year, month, day);
 * \endcode
 *
 * While all 4 parameters are passed, the handler can for instance use only the
 * first one.  The year, month and day can all be determined from the first
 * parameter which is a Date object, but because many people will explicitely
 * need the year, month or day, we pass them too to speed things up (since we
 * already know them at the time the handler is called).
 *
 * Here is an example of a not-so-complex handler:
 *
 * \code
 *	function my_DateStatus(date, year, month, day) {
 *		var str = Zapatec.Date.print(date, "%Y/%m/%d");
 *		if (str &gt;= '2000/01/01' &amp;&amp; str &lt;= '2000/12/31') {
 *			return true; // disable all dates in 2000
 *		}
 *		if (str == "1979/08/03") {
 *			return "birthday";
 *		}
 *		return false;
 *	}
 *	calendar.setDateStatusHandler(my_DateStatus);
 * \endcode
 *
 * The above handler will disable all dates in 2000 (returns true) and
 * highlight "1979/08/03" using the class "birthday".  From this example we can
 * notice that the handler can return a boolean value or a string value.  The
 * "boolean" return type is supported for backwards compatibility (function
 * setDisabledHandler, which is deprecated by setDateStatusHandler).  Here's
 * what the return value means:
 *
 * - \b true: the date will be disabled.
 * - \b false: no action taken (date stays enabled).
 * - "disabled": the date will be disabled.
 * - "other_string": the "other_string" will be added to the cell's class name.
 * - "disabled other_string": the date will be disabled and "disabled other_string"
 *	will be added to cell's class name; this helps one make a date disabled while
 *	still highlighting it in a special way.
 *
 * Note that user defined class names should have an associated CSS part
 * somewhere in the document that specifies how the days will look like;
 * otherwise, no difference will be visible.  For instance, for highlighting
 * "birthday" dates, one should also add:
 *
 * \code
 *	.birthday { color: #f00; }
 * \endcode
 *
 * somewhere in the CSS of the calling document.  (the above will make them
 * red).
 *
 * Disabled dates are not clickable; however, if one overrides the "disable"
 * CSS class, or if the cell also gets an "other_string" class that contains
 * settings that override the "disabled" class, those cells might not look
 * "disabled" but still behave so.
 *
 * \b WARNING: this function gets called 28 to 31 times each time a month is
 * displayed.  This means that if you are doing crazy computations in order to
 * determine the status of a day, things \em will slow down dramatically.  You
 * have been warned.
 *
 * <span class="attrib">@param</span> unaryFunction [function] handler that decides the status of the passed date
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.setDateStatusHandler = Zapatec.Calendar.<span class="reserved">prototype</span>.setDisabledHandler = <span class="reserved">function</span> (unaryFunction) {
	<span class="reserved">this</span>.getDateStatus = unaryFunction;
};

<span class="comment">/**
 * Configures a range of allowed dates for the calendar.  Currently, this
 * function supports setting a range on a "month granularity".  This means,
 * using it you can't disable part of a month.  Both parameters are numeric and
 * can be float.  The range is "inclusive".
 *
 * This function might seem somehow complicated, but it's designed in a way
 * that keeps backwards compatibility with the calendar v0.9.6.
 *
 * -# when the end points are integers, the full years will be included.  That
 *	 is, if you call calendar.setRange(1999, 2005) then only dates between and
 *	 including 1999/01/01 and 2005/12/31 will be allowed.
 * -# when the end points are floats, the decimal part specifies the month.
 *	 Therefore, calendar.setRange(1999.03, 2005.05) will allow dates between
 *	 and including 1999/03/01 (March 1) and 2005/05/31 (May 31).
 *
 * The above statements mean that the following two lines are equivalent:
 *
 * \code
 *	calendar.setDate(1999, 2005);		 // or
 *	calendar.setDate(1999.01, 2005.12);
 * \endcode
 *
 * <span class="attrib">@param</span> A [number] the range start point
 * <span class="attrib">@param</span> Z [number] the range end point
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.setRange = <span class="reserved">function</span> (A, Z) {
	var m,
		a = Math.min(A, Z),
		z = Math.max(A, Z);
	<span class="reserved">this</span>.minYear = m = Math.floor(a);
	<span class="reserved">this</span>.minMonth = (m == a) ? 0 : Math.ceil((a - m) * 100 - 1);
	<span class="reserved">this</span>.maxYear = Math.floor(z);
	<span class="reserved">this</span>.maxMonth = (<span class="reserved">this</span>.maxYear == z) ? 11 : Math.ceil(Math.round((z - <span class="reserved">this</span>.maxYear) * 100) - 1);
};

<span class="comment">/**
 * This function sets up the cal.multiple property initially when the flat or popup calendar is created.
 * If there are dates to be displayed or added to the first time, this property will be filled with those
 * dates at the beginning.
 *
 * multiple -- [Array] - stores the current dates for future use and appending of additional dates
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.setMultipleDates = <span class="reserved">function</span>(multiple) {
	<span class="reserved">if</span> (!multiple || typeof multiple == <span class="literal">"undefined"</span>) <span class="reserved">return</span>;

	<span class="reserved">this</span>.config.multiple = [];
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeRange) {
		var multipleRange = <span class="reserved">this</span>.config.multipleRange;
		<span class="reserved">this</span>.config.multipleRange = [];
	}
	Zapatec.Calendar.activeCalendar = <span class="reserved">this</span>;
	var ds = null;
	<span class="reserved">for</span> (var i = multiple.length; --i &gt;= 0;) {
		var d = multiple[i];
		ds = zapatecDate.print.call(<span class="reserved">this</span>, d, <span class="literal">"%Y%m%d"</span>);
		<span class="reserved">this</span>.config.multiple[ds] = d;
		<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeRange) <span class="reserved">this</span>._findDateFormMultiple(ds, multipleRange);
	}
};

<span class="comment">/**
 * Selects the passed date. If date is already selected method just returns true.
 * Passing a range is done using array with two elements, but range should go inside the array.
 * In this case if at least one date is handled correctly method returns true.
 * So for example the following code is legal:
 *  cal.selectDate(date); //select one date
 *  cal.selectDate([date1, date2]); //select array of dates
 *  cal.selectDate([[rangeStartDate, rangeEndDate]]); //select date range
 *  cal.selectDate([[rangeStartDate1, rangeEndDate1], [rangeStartDate2, rangeEndDate2]]); //selct two date ranges
 *
 * <span class="attrib">@param</span> {Object} dates - date ranges
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.selectDate = <span class="reserved">function</span> (dates) {
	var cal = <span class="reserved">this</span>;
	<span class="reserved">function</span> setDateRange(dateRange) {
		var count = 0;
		<span class="reserved">for</span> (var i in dateRange)
			count++;
		<span class="reserved">if</span> (count == 0) {
			dateRange[0] = dateRange;
		}
		<span class="reserved">if</span> (count != 2) {
			<span class="reserved">for</span> (var i in dateRange)
				<span class="reserved">if</span> (typeof dateRange[i] != <span class="literal">'array'</span>)
					cal.toggleMultipleDate(new Date(dateRange[i]))
				<span class="reserved">else</span>
					<span class="reserved">return</span> false;
			<span class="reserved">return</span> true;
		}

		var maxDate = dateRange[0] &lt; dateRange[1] ? dateRange[1] : dateRange[0];
		var minDate = dateRange[0] &lt; dateRange[1] ? dateRange[0] : dateRange[1];
		<span class="reserved">for</span> (var i = new Date(minDate); i &lt;= maxDate; i.setDate(i.getDate() + 1))
			cal.toggleMultipleDate(new Date(i));
		<span class="reserved">return</span> true;
	}

	var count = 0;
	<span class="reserved">for</span> (var i in dates)
		count++;
	<span class="reserved">if</span> (count == 0)
		dates[0] = dates;

	<span class="reserved">if</span> (<span class="reserved">this</span>.config.multiple)
		<span class="reserved">for</span> (var i in dates) {
			<span class="reserved">if</span> (!setDateRange(dates[i]))
				<span class="reserved">return</span> false;
		}
	<span class="reserved">else</span> {
		var tmpDate = dates[0];
		<span class="reserved">while</span> (tmpDate[0])
			tmpDate = tmpDate[0];
		<span class="reserved">this</span>.navigateTo(tmpDate);
	}
}

<span class="comment">/**
 *
 * <span class="attrib">@param</span> {Object} dates
 */</span>
Zapatec.Calendar.deselectDate = <span class="reserved">function</span> (dates) {
}


<span class="comment">/**
 * Call the calendar's callback function, if defined.  The passed argument
 * is the date object. This is a public function meant to be invoked by the user so that s/he can
 * have more controls on what to do with the dates selected.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.submitFlatDates = <span class="reserved">function</span>()
{
	<span class="reserved">if</span> (typeof <span class="reserved">this</span>.config.flatCallback == <span class="literal">"function"</span>) {
		<span class="comment">//Specify the pre-set sorting so that Zapatec.Utils will sort the multiple dates accordingly.</span>
		<span class="comment">//Default to "asc" if it does not equal to "asc" or "desc".</span>
		Zapatec.Calendar.sortOrder = (<span class="reserved">this</span>.config.sortOrder != <span class="literal">"asc"</span> &amp;&amp; <span class="reserved">this</span>.config.sortOrder != <span class="literal">"desc"</span> &amp;&amp; <span class="reserved">this</span>.config.sortOrder != <span class="literal">"none"</span>) ? <span class="literal">"none"</span> : <span class="reserved">this</span>.config.sortOrder;

		<span class="reserved">if</span> (<span class="reserved">this</span>.config.multiple &amp;&amp; (Zapatec.Calendar.sortOrder != <span class="literal">"none"</span>)) {
			var dateArray = new Array();

			<span class="reserved">for</span> (var i in <span class="reserved">this</span>.config.multiple) {
				var currentDate = <span class="reserved">this</span>.config.multiple[i];
				<span class="comment">// sometimes the date is not actually selected, that's why we need to check.</span>
				<span class="reserved">if</span> (currentDate) {
					<span class="comment">// and push it in the "dateArray", in case one triggers the calendar again.</span>
					dateArray[dateArray.length] = currentDate;
				}
				<span class="comment">//Now let's sort the dateArray array</span>
				dateArray.sort(Zapatec.Calendar.compareDates);
			}

			<span class="reserved">this</span>.config.multiple = {};
			<span class="reserved">for</span> (var i = 0; i &lt; dateArray.length; i++) {
				var d = dateArray[i];
				<span class="comment">//var ds = zapatecDate.print.call(this, d, "%Y%m%d%H%M");</span>
				var ds = zapatecDate.print.call(<span class="reserved">this</span>, d, <span class="literal">"%Y%m%d"</span>);
				<span class="reserved">this</span>.config.multiple[ds] = d;
				<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeRange) <span class="reserved">this</span>._findDateFormMultiple(ds);
			}
		} <span class="comment">//Else no need to sort the multiple dates.</span>
		<span class="reserved">this</span>.config.flatCallback(<span class="reserved">this</span>);
	}
}

<span class="comment">/**
 * Call the calendar's "onSelected" handler, if defined.  The passed arguments
 * are the date object and a string with the date formatted by the specifier in
 * calendar.dateFormat.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.callHandler = <span class="reserved">function</span> () {
	<span class="reserved">if</span> (<span class="reserved">this</span>.onSelected) {
		<span class="reserved">this</span>.onSelected(<span class="reserved">this</span>,
			zapatecDate.print.call(<span class="reserved">this</span>, <span class="reserved">this</span>.config.date, <span class="reserved">this</span>.dateFormat));
	}
};

<span class="comment">/**
 * This function updates the calendar history and saves the cookie.  The
 * history is a string containing date and time formatted as "%Y/%m/%d/%H/%M"
 * (that is, all time parts separated by slashes, in a "most significant to
 * least significant order").  Further, such formats are separated by commas,
 * and the current calendar date is added the first, then the cookie saved.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.updateHistory = <span class="reserved">function</span> () {
	var a, i, d, tmp, s, str = <span class="literal">""</span>, len = <span class="reserved">this</span>.config.prefs.hsize - 1;
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.prefs.history) {
		a = <span class="reserved">this</span>.config.prefs.history.split(/,/);
		i = 0;
		<span class="reserved">while</span> (i &lt; len &amp;&amp; (tmp = a[i++])) {
			s = tmp.split(/\<span class="comment">//);</span>
			d = new Date(parseInt(s[0], 10), parseInt(s[1], 10) - 1, parseInt(s[2], 10),
				parseInt(s[3], 10), parseInt(s[4], 10));
			<span class="reserved">if</span> (!Zapatec.Date.dateEqualsTo(d, <span class="reserved">this</span>.config.date))
				str += <span class="literal">","</span> + tmp;
		}
	}
	<span class="reserved">this</span>.config.prefs.history = zapatecDate.print.call(<span class="reserved">this</span>, <span class="reserved">this</span>.config.date, <span class="literal">"%Y/%m/%d/%H/%M"</span>) + str;
	Zapatec.Calendar.savePrefs(<span class="reserved">this</span>.id);
};

<span class="comment">/**
 * Show "ABOUT" information
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.callHelpHandler = <span class="reserved">function</span> () {
	var cal = <span class="reserved">this</span>;
	var text = Zapatec.Calendar.i18n(<span class="literal">"ABOUT"</span>, null, cal);
	<span class="reserved">if</span> (typeof text != <span class="literal">"undefined"</span>) {
		text += cal.config.showsTime ? Zapatec.Calendar.i18n(<span class="literal">"ABOUT_TIME"</span>, null, cal) : <span class="literal">""</span>;
	} <span class="reserved">else</span> {
		<span class="comment">// FIXME: this should be removed as soon as lang files get updated!</span>
		text = <span class="literal">"Help and about box text is not translated into this language.\n"</span> +
				 <span class="literal">"If you know this language and you feel generous please update\n"</span> +
				 <span class="literal">"the corresponding file in \"</span>lang\<span class="literal">" subdir to match calendar-en.js\n"</span> +
				 <span class="literal">"and send it back to &lt;support@zapatec.com&gt; to get it into the distribution  ;-)\n\n"</span> +
				 <span class="literal">"Thank you!\n"</span> +
				 <span class="literal">"http://www.zapatec.com\n"</span>;
	}
	alert(text);
}

<span class="comment">/**
 * Calls the calendar's onClose handler, if present.  Either way, this function
 * calls updateHistory() in order to update the history cookie.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.callCloseHandler = <span class="reserved">function</span> () {
	<span class="reserved">if</span> (<span class="reserved">this</span>.dateClicked &amp;&amp; !<span class="reserved">this</span>.config.noHistory) {
		<span class="reserved">this</span>.updateHistory();
	}
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.onClose) {
		<span class="reserved">this</span>.config.onClose(<span class="reserved">this</span>);
	}
	<span class="reserved">this</span>.hideShowCovered();
};

<span class="comment">/** Removes the calendar object from the DOM tree and destroys it. */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.destroy = <span class="reserved">function</span> () {
	<span class="reserved">this</span>.hide();	 <span class="comment">// this also removes keyboard events :-\</span>
	Zapatec.Utils.destroy(<span class="reserved">this</span>.element);
	Zapatec.Utils.destroy(<span class="reserved">this</span>.WCH);
	Zapatec.Calendar.activeCalendar = null;
};

<span class="comment">/**
 * Moves the calendar element to a different section in the DOM tree (changes
 * its parent).  This might be useful for flat calendars.
 *
 * <span class="attrib">@param</span> new_parent [HTMLElement] the new parent for the calendar.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.reparent = <span class="reserved">function</span> (new_parent) {
	var el = <span class="reserved">this</span>.element;
	el.parentNode.removeChild(el);
	new_parent.appendChild(el);
};

<span class="comment">/**
 * This gets called when the user presses a mouse button anywhere in the
 * document, if the calendar is shown.  If the click was outside the open
 * calendar this function closes it and stops the event from propagating.
 *
 * <span class="attrib">@param</span> ev [Event] the event object.
 * <span class="attrib">@return</span> false if the event is stopped.
 */</span>
Zapatec.Calendar._checkCalendar = <span class="reserved">function</span>(ev) {
	var cal = Zapatec.Calendar.activeCalendar;

	<span class="reserved">if</span> (!cal) {
		<span class="reserved">return</span> false;
	}

	<span class="comment">// Opera call this justAfterCreation</span>
	<span class="comment">/*if (Zapatec.is_opera &amp;&amp; cal.justCreate) {
	 cal.justCreate = false;
	 return;
	 }*/</span>

	var el = Zapatec.is_ie ? Zapatec.Utils.getElement(ev) : Zapatec.Utils.getTargetElement(ev);
	<span class="reserved">for</span> (; el != null &amp;&amp; el != cal.element; el = el.parentNode) ;
	<span class="reserved">if</span> (el == null) {
		<span class="comment">// calls closeHandler which should hide the calendar.</span>
		cal.callCloseHandler();
	}
};

<span class="comment">/**
 * Updates the calendar "WCH" (windowed controls hider).  A WCH is an
 * "invention" (read: "miserable hack") that works around one of the most
 * common and old bug in Internet Explorer: the SELECT boxes or IFRAMES show on
 * top of any other HTML element.  This function makes sure that the WCH covers
 * correctly the calendar element and another element if passed.
 *
 * <span class="attrib">@param</span> other_el [HTMLElement, optional] a second element that the WCH should cover.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.updateWCH = <span class="reserved">function</span>(other_el) {
	Zapatec.Utils.setupWCH_el(<span class="reserved">this</span>.WCH, <span class="reserved">this</span>.element, other_el);
};

<span class="comment">/**
 * Displays a hidden calendar.  It walks quickly through the HTML elements and
 * makes sure that they don't have "hover" or "active" class names that might
 * be there from a previous time the same calendar was displayed (exept rowhilite ;)).
 * This function also calls updateWCH() and hideShowCovered() to workaround
 * miserable IE bugs.
 *
 * If the calendar is a popup calendar and doesn't have the "noGrab" property
 * set, this function also adds document event handlers to intercept key events
 * or to close the calendar when one clicks outside it.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.show = <span class="reserved">function</span> () {
	<span class="reserved">if</span> (!<span class="reserved">this</span>.table)
		<span class="reserved">this</span>.create();
	var rows = <span class="reserved">this</span>.table.getElementsByTagName(<span class="literal">"tr"</span>);
	<span class="reserved">for</span> (var i = rows.length; i &gt; 0;) {
		var row = rows[--i];
		<span class="reserved">if</span> (/zpCalendar\d{1,3}RootTableTR\d{1,2}/.test(row.id)) {
			continue;
		}
		Zapatec.Utils.removeClass(row, <span class="literal">"rowhilite"</span>);
		var cells = row.getElementsByTagName(<span class="literal">"td"</span>);
		<span class="reserved">for</span> (var j = cells.length; j &gt; 0;) {
			var cell = cells[--j];
			<span class="reserved">if</span> (/zpCalendar\d{1,3}RootTableTR\d{1,2}TD\d{1,2}/.test(cell.id)) {
				continue;
			}
			Zapatec.Utils.removeClass(cell, <span class="literal">"hilite"</span>);
			Zapatec.Utils.removeClass(cell, <span class="literal">"active"</span>);
		}
	}

	<span class="comment">// Show with effects</span>

	<span class="reserved">if</span> (<span class="reserved">this</span>.element.style.display != <span class="literal">"block"</span>) {
		<span class="reserved">this</span>.element.style.visibility = <span class="literal">"hidden"</span>;
		<span class="reserved">this</span>.element.style.display = <span class="literal">"block"</span>;
	}
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.showEffect.length &gt; 0) {
		<span class="reserved">this</span>.showContainer(<span class="reserved">this</span>.config.showEffect, <span class="reserved">this</span>.config.showEffectSpeed, <span class="reserved">this</span>.config.showEffectOnFinish);
	} <span class="reserved">else</span> {
		<span class="comment">// Enable trigger element</span>
		<span class="reserved">if</span> (<span class="reserved">this</span>.triggerEl) {
			<span class="reserved">this</span>.triggerEl.disabled = false;
		}
	}
	<span class="reserved">if</span> (<span class="reserved">this</span>.element.style.visibility == <span class="literal">"hidden"</span>) {
		<span class="reserved">this</span>.element.style.visibility = <span class="literal">""</span>;
	}

	<span class="reserved">this</span>.hidden = false;

	<span class="reserved">if</span> (<span class="reserved">this</span>.isPopup) {
		<span class="reserved">this</span>.updateWCH();
		Zapatec.Calendar.activeCalendar = <span class="reserved">this</span>;
		<span class="reserved">if</span> (!<span class="reserved">this</span>.config.noGrab) {
			Zapatec.Utils.addEvent(window.document, <span class="literal">"keydown"</span>, Zapatec.Calendar._keyEvent);
			Zapatec.Utils.addEvent(window.document, <span class="literal">"keypress"</span>, Zapatec.Calendar._keyEvent);
			<span class="comment">//this.justCreate = true;</span>
			Zapatec.Utils.addEvent(window.document, <span class="literal">"mousedown"</span>, Zapatec.Calendar._checkCalendar);
		}
	}

	<span class="reserved">this</span>.hideShowCovered();
};

<span class="comment">/**
 * Set activeCalendar = null after hide effect
 * <span class="attrib">@param</span> {Object} calId - calendar id
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.onHide = <span class="reserved">function</span> () {
	Zapatec.Calendar.activeCalendar = null;

	<span class="comment">// Romove rowhilite class</span>
	<span class="reserved">if</span> (<span class="reserved">this</span>.lastRowHilite) {
		Zapatec.Utils.removeClass(<span class="reserved">this</span>.lastRowHilite, <span class="literal">"rowhilite"</span>);
	}
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.hideEffectOnFinish)
		<span class="reserved">this</span>.config.hideEffectOnFinish

	<span class="comment">// IE WCH hack</span>
	<span class="reserved">if</span> (Zapatec.Utils.__wch_id &gt; 0)
		Zapatec.Utils.hideWCH(document.getElementById(<span class="literal">"WCH"</span> + Zapatec.Utils.__wch_id));

	<span class="comment">// Enable trigger element</span>
	<span class="reserved">if</span> (<span class="reserved">this</span>.triggerEl) {
		<span class="reserved">this</span>.triggerEl.disabled = false;
	}
}

<span class="comment">/**
 * Hides the calendar.  Also removes any "hilite" from the class of any TD
 * element.  Unregisters the document event handlers for key presses and
 * mousedown.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.hide = <span class="reserved">function</span> () {
	<span class="reserved">if</span> (<span class="reserved">this</span>.isPopup) {
		Zapatec.Utils.removeEvent(window.document, <span class="literal">"keydown"</span>, Zapatec.Calendar._keyEvent);
		Zapatec.Utils.removeEvent(window.document, <span class="literal">"keypress"</span>, Zapatec.Calendar._keyEvent);
		Zapatec.Utils.removeEvent(window.document, <span class="literal">"mousedown"</span>, Zapatec.Calendar._checkCalendar);
	}

	Zapatec.Utils.hideWCH(<span class="reserved">this</span>.WCH);
	<span class="reserved">this</span>.hidden = true;
	<span class="reserved">this</span>.hideShowCovered();

	<span class="reserved">if</span> (<span class="reserved">this</span>.config.hideEffect.length &gt; 0) {
		<span class="reserved">if</span> (<span class="reserved">this</span>.triggerEl) {
			<span class="reserved">this</span>.triggerEl.disabled = true;
		}
		<span class="reserved">this</span>.hideContainer(<span class="reserved">this</span>.config.hideEffect, <span class="reserved">this</span>.config.hideEffectSpeed, new Function(<span class="literal">"Zapatec.Widget.getWidgetById("</span> + <span class="reserved">this</span>.id + <span class="literal">").onHide()"</span>));
	}
	<span class="reserved">else</span> <span class="reserved">if</span> (<span class="reserved">this</span>.element) {
		<span class="reserved">this</span>.element.style.display = <span class="literal">"none"</span>;
		<span class="comment">// Romove rowhilite class</span>
		<span class="reserved">if</span> (<span class="reserved">this</span>.lastRowHilite) {
			Zapatec.Utils.removeClass(<span class="reserved">this</span>.lastRowHilite, <span class="literal">"rowhilite"</span>);
		}
	}


};

<span class="comment">/**
 * Shows the calendar at a given absolute position (beware that, depending on
 * the calendar element style -- position property -- this might be relative to
 * the parent's containing rectangle).
 *
 * <span class="attrib">@param</span> x [int] the X position
 * <span class="attrib">@param</span> y [int] the Y position
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.showAt = <span class="reserved">function</span> (x, y) {
	<span class="reserved">if</span> (<span class="reserved">this</span>.element) {
		var s = <span class="reserved">this</span>.element.style;
		s.left = x + <span class="literal">"px"</span>;
		s.top = y + <span class="literal">"px"</span>;
	}

	<span class="reserved">this</span>.show();
};

<span class="comment">/**
 * This function displays the calendar near a given "anchor" element, according
 * to some rules passed in \em opts.  The \em opts argument is a string
 * containing one or 2 letters.  The first letter decides the vertical
 * alignment, and the second letter decides the horizontal alignment relative
 * to the anchor element.  Following we will describe these options; in parens
 * we will use simple descriptions like "top to bottom" which means that the
 * top margin of the calendar is aligned with the bottom margin of the object.
 *
 * \b Vertical align:
 *
 * - T -- the calendar is completely above the element (bottom to top)
 * - t -- the calendar is above the element but might overlap it (bottom to bottom)
 * - C -- the calendar is vertically centered to the element
 * - b -- the calendar is below the element but might overlap it (top to top)
 * - B -- the calendar is completely below the element (top to bottom)
 *
 * \b Horizontal align (defaults to 'l' if no letter passed):
 *
 * - L -- the calendar is completely to the left of the element (right to left)
 * - l -- the calendar is to the left of the element but might overlap it (right to right)
 * - C -- the calendar is horizontally centered to the element
 * - r -- the calendar is to the right of the element but might overlap it (left to left)
 * - R -- the calendar is completely to the right of the element (left to right)
 *
 * <span class="attrib">@param</span> el [HTMLElement] the anchor element
 * <span class="attrib">@param</span> opts [string, optional] the align options, as described above.  Defaults to "Bl" if nothing passed.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.showAtElement = <span class="reserved">function</span> (el, opts) {
	var self = <span class="reserved">this</span>;
	var p = Zapatec.Utils.getElementOffsetRelative(el);
	<span class="reserved">if</span> (!opts || typeof opts != <span class="literal">"string"</span>) {
		<span class="reserved">this</span>.showAt(p.x, p.y + el.offsetHeight);
		<span class="reserved">return</span> true;
	}
	self.element.style.visibility = <span class="literal">"hidden"</span>;
	self.element.style.display = <span class="literal">"block"</span>;
	var w = self.element.offsetWidth;
	var h = self.element.offsetHeight;
	self.element.style.display = <span class="literal">"none"</span>;
	self.element.style.visibility = <span class="literal">""</span>;
	var valign = opts.substr(0, 1);
	var halign = <span class="literal">"l"</span>;
	<span class="reserved">if</span> (opts.length &gt; 1) {
		halign = opts.substr(1, 1);
	}
	<span class="comment">// vertical alignment</span>
	switch (valign) {
		case <span class="literal">"T"</span>: p.y -= h; break;
		case <span class="literal">"B"</span>: p.y += el.offsetHeight; break;
		case <span class="literal">"C"</span>: p.y += (el.offsetHeight - h) / 2; break;
		case <span class="literal">"t"</span>: p.y += el.offsetHeight - h; break;
		case <span class="literal">"b"</span>: break; <span class="comment">// already there</span>
	}
	<span class="comment">// horizontal alignment</span>
	switch (halign) {
		case <span class="literal">"L"</span>: p.x -= w; break;
		case <span class="literal">"R"</span>: p.x += el.offsetWidth; break;
		case <span class="literal">"C"</span>: p.x += (el.offsetWidth - w) / 2; break;
		case <span class="literal">"l"</span>: p.x += el.offsetWidth - w; break;
		case <span class="literal">"r"</span>: break; <span class="comment">// already there</span>
	}
	p.width = w;
	p.height = h;
	self.monthsCombo.style.display = <span class="literal">"none"</span>;
	self.showAt(p.x, p.y);
};

<span class="comment">/**
 * Print date with timeRange paramiter
 * <span class="attrib">@param</span> {Object} date
 * <span class="attrib">@param</span> {Object} format
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.printWith2Time = <span class="reserved">function</span> (date, date1, format) {
	<span class="comment">// For 2 times print ours, minutes, seconds</span>
	<span class="reserved">if</span> (<span class="reserved">this</span>.config.timeRange) {
		<span class="reserved">if</span> (!date1) date1 = date;
		var s = {};
		var hr = date1.getHours();
		var pm = (hr &gt;= 12);
		var ir = (pm) ? (hr - 12) : hr;
		var dy = Zapatec.Date.getDayOfYear(date1);
		<span class="reserved">if</span> (ir == 0)
			ir = 12;
		var min = date1.getMinutes();
		var sec = date1.getSeconds();
		s[<span class="literal">"%H1"</span>] = (hr &lt; 10) ? (<span class="literal">"0"</span> + hr) : hr; <span class="comment">// hour, range 00 to 23 (24h format)</span>
		s[<span class="literal">"%I1"</span>] = (ir &lt; 10) ? (<span class="literal">"0"</span> + ir) : ir; <span class="comment">// hour, range 01 to 12 (12h format)</span>
		s[<span class="literal">"%k1"</span>] = hr ? hr : <span class="literal">"0"</span>; <span class="comment">// hour, range 0 to 23 (24h format)</span>
		s[<span class="literal">"%l1"</span>] = ir;		 <span class="comment">// hour, range 1 to 12 (12h format)</span>
		s[<span class="literal">"%M1"</span>] = (min &lt; 10) ? (<span class="literal">"0"</span> + min) : min; <span class="comment">// minute, range 00 to 59</span>
		s[<span class="literal">"%s1"</span>] = Math.floor(date.getTime() / 1000);
		s[<span class="literal">"%S1"</span>] = (sec &lt; 10) ? (<span class="literal">"0"</span> + sec) : sec; <span class="comment">// seconds, range 00 to 59</span>
		var str = format;
		var re = /%.1/g;
		var a = str.match(re) || [];
		<span class="reserved">for</span> (var i = 0; i &lt; a.length; i++) {
			var tmp = s[a[i]];
			<span class="reserved">if</span> (tmp) {
				re = new RegExp(a[i], <span class="literal">'g'</span>);
				str = str.replace(re, tmp);
			}
		}
		<span class="reserved">return</span> zapatecDate.print.call(<span class="reserved">this</span>, date, str);
	}
	<span class="reserved">else</span>
		<span class="reserved">return</span> zapatecDate.print.call(<span class="reserved">this</span>, date, format);
}

<span class="comment">/**
 * Customizes the date format that will be reported to the onSelect handler.
 * The format string is described in Zapatec.Date.print().
 *
 * <span class="attrib">@param</span> str [string] the date format.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.setDateFormat = <span class="reserved">function</span> (str) {
	<span class="reserved">this</span>.dateFormat = str;
};

<span class="comment">/** Customizes the tooltip date format.  See
 * Zapatec.Calendar.prototype.setDateFormat() for a description of the \em str
 * format.
 *
 * <span class="attrib">@param</span> str [string] the "tooltip" date format
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.setTtDateFormat = <span class="reserved">function</span> (str) {
	<span class="reserved">this</span>.ttDateFormat = str;
};

<span class="comment">/**
 * Tries to identify the date represented in a string.  If successful it also
 * calls this.setDate which moves the calendar to the given date.
 *
 * <span class="attrib">@param</span> str [string] a date
 * <span class="attrib">@param</span> fmt [string] the format to try to parse \em str in
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.parseDate = <span class="reserved">function</span> (str, fmt) {
	<span class="reserved">if</span> (!str)
		<span class="reserved">return</span> <span class="reserved">this</span>.setDate(<span class="reserved">this</span>.config.date);
	<span class="reserved">if</span> (!fmt)
		fmt = <span class="reserved">this</span>.dateFormat;
	var date = zapatecDate.parseDate.call(<span class="reserved">this</span>, str, fmt);
	<span class="reserved">return</span> <span class="reserved">this</span>.setDate(date);
};

<span class="comment">/**
 * This function hides or shows "windowed controls" accordingly so that the
 * calendar isn't obtured by any such control.  Historically, this function was
 * used for any browser.  It simply walks through all SELECT, IFRAME and APPLET
 * elements present in the DOM, checks if they intersect the calendar and hides
 * them if so or makes them visible otherwise.  This approacy has a number of
 * problems, the most important being that if the end-user's code contains a
 * SELECT which is already hidden and it must stay hidden, it will still be
 * made visible when the calendar closes.  The other obvious problem is that
 * there's an ugly effect generated by elements that suddenly (dis)appear when
 * you drag the calendar around the screen.
 *
 * Currently this function is only used on IE5.0/Windows, browser that leaves
 * no room for a better workaround to this problem.  For IE5.5+/Windows an
 * workaround is possible, albeit amazingly ugly (WCH).  For other browsers
 * such crazy techniques are not anymore useful because the bugs related to
 * windowed controls were fixed.
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>.hideShowCovered = <span class="reserved">function</span> () {
	<span class="reserved">if</span> (!Zapatec.is_ie5)
		<span class="reserved">return</span>;
	var self = <span class="reserved">this</span>;
	<span class="reserved">function</span> getVisib(obj) {
		var value = obj.style.visibility;
		<span class="reserved">if</span> (!value) {
			<span class="reserved">if</span> (window.document.defaultView &amp;&amp; typeof (window.document.defaultView.getComputedStyle) == <span class="literal">"function"</span>) { <span class="comment">// Gecko, W3C</span>
				<span class="reserved">if</span> (!Zapatec.is_khtml)
					value = window.document.defaultView.
						getComputedStyle(obj, <span class="literal">""</span>).getPropertyValue(<span class="literal">"visibility"</span>);
				<span class="reserved">else</span>
					value = <span class="literal">''</span>;
			} <span class="reserved">else</span> <span class="reserved">if</span> (obj.currentStyle) { <span class="comment">// IE</span>
				value = obj.currentStyle.visibility;
			} <span class="reserved">else</span>
				value = <span class="literal">''</span>;
		}
		<span class="reserved">return</span> value;
	}
	;

	var tags = [<span class="literal">"applet"</span>, <span class="literal">"iframe"</span>, <span class="literal">"select"</span>];
	var el = self.element;

	var p = Zapatec.Utils.getAbsolutePos(el);
	var EX1 = p.x;
	var EX2 = el.offsetWidth + EX1;
	var EY1 = p.y;
	var EY2 = el.offsetHeight + EY1;

	<span class="reserved">for</span> (var k = tags.length; k &gt; 0;) {
		var ar = window.document.getElementsByTagName(tags[--k]);
		var cc = null;

		<span class="reserved">for</span> (var i = ar.length; i &gt; 0;) {
			cc = ar[--i];

			p = Zapatec.Utils.getAbsolutePos(cc);
			var CX1 = p.x;
			var CX2 = cc.offsetWidth + CX1;
			var CY1 = p.y;
			var CY2 = cc.offsetHeight + CY1;

			<span class="reserved">if</span> (self.hidden || (CX1 &gt; EX2) || (CX2 &lt; EX1) || (CY1 &gt; EY2) || (CY2 &lt; EY1)) {
				<span class="reserved">if</span> (!cc.__msh_save_visibility) {
					cc.__msh_save_visibility = getVisib(cc);
				}
				cc.style.visibility = cc.__msh_save_visibility;
			} <span class="reserved">else</span> {
				<span class="reserved">if</span> (!cc.__msh_save_visibility) {
					cc.__msh_save_visibility = getVisib(cc);
				}
				cc.style.visibility = <span class="literal">"hidden"</span>;
			}
		}
	}
};

<span class="comment">/**
 * This function displays the week day names in the calendar header, according
 * to the current "firstDay".
 */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>._displayWeekdays = <span class="reserved">function</span> () {
	var fdow = <span class="reserved">this</span>.config.firstDay;
	var cell = <span class="reserved">this</span>.firstDayName;
	var weekend = Zapatec.Calendar.i18n(<span class="literal">"WEEKEND"</span>, null, <span class="reserved">this</span>);
	<span class="comment">//displaying one row of day names for every month in the row</span>
	<span class="reserved">for</span> (k = 1; (k &lt;= <span class="reserved">this</span>.config.monthsInRow) &amp;&amp; (cell); ++k) {
		<span class="reserved">for</span> (var i = 0; i &lt; 7; i++) {
			cell.className = <span class="literal">"day name"</span>;
			<span class="reserved">if</span> ((!<span class="reserved">this</span>.config.weekNumbers) &amp;&amp; (i == 0) &amp;&amp; (k != 1)) {
				Zapatec.Utils.addClass(cell, <span class="literal">"month-left-border"</span>);
			}
			<span class="reserved">if</span> ((i == 6) &amp;&amp; (k != <span class="reserved">this</span>.config.monthsInRow)) {
				Zapatec.Utils.addClass(cell, <span class="literal">"month-right-border"</span>);
			}
			var realday = (i + fdow) % 7;

			<span class="reserved">if</span> ((!<span class="reserved">this</span>.config.disableFdowChange) &amp;&amp; ((<span class="reserved">this</span>.config &amp;&amp; <span class="reserved">this</span>.config.fdowClick) || i)) {
				<span class="reserved">if</span> (Zapatec.Calendar.i18n(<span class="literal">"DAY_FIRST"</span>, null, <span class="reserved">this</span>) != null) {
					cell.ttip = Zapatec.Calendar.i18n(<span class="literal">"DAY_FIRST"</span>, null, <span class="reserved">this</span>).replace(<span class="literal">"%s"</span>, Zapatec.Calendar.i18n(realday, <span class="literal">"dn"</span>, <span class="reserved">this</span>));
				}
				cell.navtype = 100;
				cell.calendar = <span class="reserved">this</span>;
				cell.fdow = realday;
				Zapatec.Calendar._add_evs(cell);
			}
			<span class="reserved">if</span> ((weekend != null) &amp;&amp; (weekend.indexOf(realday.toString()) != -1)) {
				Zapatec.Utils.addClass(cell, <span class="literal">"weekend"</span>);
			}
			cell.innerHTML = Zapatec.Calendar.i18n((i + fdow) % 7, <span class="literal">"sdn"</span>, <span class="reserved">this</span>);
			cell = cell.nextSibling;
		}
		<span class="reserved">if</span> (<span class="reserved">this</span>.config.weekNumbers &amp;&amp; cell) {
			cell = cell.nextSibling;
		}
	}
};


<span class="comment">/**
 * Compare two dates in either ascending or descending order. To be used for
 * the multiple dates feature. This function is passed as an argument to the
 * sort routine which calls it to compare dates.
 *
 * <span class="attrib">@param</span> date1 [date] first date
 * <span class="attrib">@param</span> date2 [date] second date
 */</span>
Zapatec.Calendar.compareDates = <span class="reserved">function</span>(date1, date2)
{
	<span class="reserved">if</span> (Zapatec.Calendar.sortOrder == <span class="literal">"asc"</span>)
		<span class="reserved">return</span> date1 - date2;
	<span class="reserved">else</span> <span class="comment">//"desc"ending order</span>
		<span class="reserved">return</span> date2 - date1;
}

<span class="comment">/** \internal Hides all combo boxes that might be displayed. */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>._hideCombos = <span class="reserved">function</span> () {
	<span class="reserved">if</span> (<span class="reserved">this</span>.monthsCombo.style.display != <span class="literal">"none"</span>)
		var combo = <span class="reserved">this</span>.monthsCombo;
	<span class="reserved">else</span> <span class="reserved">if</span> (<span class="reserved">this</span>.yearsCombo.style.display != <span class="literal">"none"</span>)
		var combo = <span class="reserved">this</span>.yearsCombo;
	<span class="reserved">else</span> <span class="reserved">if</span> (<span class="reserved">this</span>.histCombo.style.display != <span class="literal">"none"</span>)
		var combo = <span class="reserved">this</span>.histCombo;
	<span class="reserved">if</span> (combo)
		<span class="reserved">for</span> (var i = combo.firstChild; i; i = i.nextSibling) {
			var m = i.month;
			Zapatec.Utils.removeClass(i, <span class="literal">"hilite"</span>);
			Zapatec.Utils.removeClass(i, <span class="literal">"active"</span>);
			Zapatec.Utils.removeClass(i, <span class="literal">"disabled"</span>);
		}

	<span class="reserved">this</span>.monthsCombo.style.display = <span class="literal">"none"</span>;
	<span class="reserved">this</span>.yearsCombo.style.display = <span class="literal">"none"</span>;
	<span class="reserved">this</span>.histCombo.style.display = <span class="literal">"none"</span>;
	<span class="reserved">this</span>.updateWCH();
};

<span class="comment">/** \internal Starts dragging the element. */</span>
Zapatec.Calendar.<span class="reserved">prototype</span>._dragStart = <span class="reserved">function</span> (ev) {
	ev || (ev = window.event);
	<span class="reserved">if</span> (<span class="reserved">this</span>.dragging) {
		<span class="reserved">return</span>;
	}
	<span class="reserved">this</span>.dragging = true;
	var posX = ev.clientX + window.document.body.scrollLeft;
	var posY = ev.clientY + window.document.body.scrollTop;
	var st = <span class="reserved">this</span>.element.style;
	<span class="reserved">this</span>.xOffs = posX - parseInt(st.left);
	<span class="reserved">this</span>.yOffs = posY - parseInt(st.top);
	Zapatec.Utils.addEvent(window.document, <span class="literal">"mousemove"</span>, Zapatec.Calendar.calDragIt);
	Zapatec.Utils.addEvent(window.document, <span class="literal">"mouseover"</span>, Zapatec.Calendar.calDragIt);
	Zapatec.Utils.addEvent(window.document, <span class="literal">"mouseup"</span>, Zapatec.Calendar.calDragEnd);
};

<span class="comment">/**
 * Show error message
 * <span class="attrib">@private</span>
 * <span class="attrib">@param</span> [string] "Human readable error description"
 */</span>
Zapatec.Calendar.submitErrorFunc = <span class="reserved">function</span>(oError) {
	var oMsg = <span class="literal">"Calendar "</span>;
	<span class="reserved">if</span> (typeof oError.id != <span class="literal">"undefined"</span>)
		oMsg += <span class="literal">"("</span> + oError.id + <span class="literal">") "</span>;
	<span class="reserved">if</span> (typeof oError.source != <span class="literal">"undefined"</span>)
		oMsg += oError.source;
	<span class="reserved">else</span>
		oMsg += <span class="literal">"unknown"</span>;
	oMsg += <span class="literal">" error"</span>;
	oMsg += <span class="literal">"\n"</span> + oError.errorDescription;

	alert(oMsg);
};
</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b>Zapatec Calendar</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Thu May 21 12:19:39 2009</div>
</body>
</html>
